Skip to content

Commit

Permalink
adding support for estimated finishing time
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortega-Dan committed Feb 7, 2023
1 parent 8810910 commit 060b81a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,24 @@ function convertDecimalHoursToTimeFormat(hoursInDecimalFormat) {
return "" + parseInt(hoursInDecimalFormat) + ":" + ("" + parseInt((hoursInDecimalFormat - parseInt(hoursInDecimalFormat)) * 60)).padStart(2, "0")
}

function showHoursDiffTo(hoursSum, hoursThreshold, label) {
function showHoursDiffTo(hoursSum, hoursThreshold, label, showFinishingTime = false) {

if ((hoursThreshold - hoursSum) < 0) {
alert("[" + label + "]\n\nYou've worked " +
convertDecimalHoursToTimeFormat((hoursThreshold - hoursSum) * -1) + " extra hours")
} else {
alert("[" + label + "]\n\nOnly " + convertDecimalHoursToTimeFormat(hoursThreshold - hoursSum) + " hours missing")
var timeDiffString = convertDecimalHoursToTimeFormat(hoursThreshold - hoursSum)

var dateTime = new Date()

dateTime.setHours(dateTime.getHours() + parseInt(timeDiffString.split(":")[0]))
dateTime.setMinutes(dateTime.getMinutes() + parseInt(timeDiffString.split(":")[1]))

var hours = dateTime.getHours()
alert("[" + label + "]\n\n" + timeDiffString + " hours missing" +
(showFinishingTime ?
"\n\nFinishing by " + (hours == 12 ? hours : hours % 12) + ":" + ("" + dateTime.getMinutes()).padStart(2, "0") + (hours / 12 < 1.0 ? " am" : " pm") : ""))

}

}
Expand All @@ -62,7 +73,7 @@ function showHoursDiffTo(hoursSum, hoursThreshold, label) {
$("html").keydown(function (event) {

// Running functionality con Ctrl + i or Ctrl + k (case insensitive)
if (event.altKey === true && (event.code === "KeyI" | event.code === "KeyK")) {
if (event.altKey === true && (event.code === "KeyI" || event.code === "KeyK" || event.code === "KeyO")) {

event.preventDefault()
event.stopPropagation()
Expand All @@ -71,7 +82,7 @@ $("html").keydown(function (event) {
var requiredDayText

// Set the query for the current day
if (event.code === "KeyI") {
if (event.code === "KeyI" || event.code === "KeyO") {

var todaysDate = new Date()

Expand Down Expand Up @@ -185,7 +196,7 @@ $("html").keydown(function (event) {
showHoursDiffTo(calendarTimeAdder, weeklyHoursMargin, requiredDayText)
} else {
// Show hours diff for single day query
showHoursDiffTo(calendarTimeAdder, dailyHoursMargin, requiredDayText)
showHoursDiffTo(calendarTimeAdder, dailyHoursMargin, requiredDayText, event.code === "KeyO")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Calendar Hours Counter",
"description": "(For Google Calendar configured with English (US) language)",
"version": "1.9.1",
"version": "1.10.0",
"icons": {
"16": "calendar16.png",
"48": "calendar48.png",
Expand Down
6 changes: 3 additions & 3 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<body>
<h3>Calendar Hours Counter</h3>
<ul style="min-width: 350px;">
<li>Count Current Day Hours: Alt + I</li>
<li>Count Week Hours with filter: Alt + K<br>
(From there you can check for different days according to instructions).</li>
<li>Alt + I: Current Day Hours and Diff </li>
<li>Alt + O: Current Day Hours and Diff (with estimated finishing time)</li>
<li>Alt + K: Count Week Hours and Diff (with optional filter for different days according to instructions).</li>
</ul>
<p style="color: darkblue;">Works on Google Calendar for personal and enterprise versions, with English (US) language,
and United States country settings, and counts events that start and end on the same day (e.g events that don't start in a day and end in the next day or after, according to the time zone presented in the Google Calendar view evaluated).
Expand Down

0 comments on commit 060b81a

Please sign in to comment.