Comparing version 0.10.6 to 0.11.6
@@ -208,3 +208,3 @@ "use strict"; | ||
(_b = props.icon) !== null && _b !== void 0 ? _b : "", | ||
utils_1.default.getDate(), | ||
utils_1.default.getDateStr(), | ||
]; | ||
@@ -283,3 +283,3 @@ const resp = yield (0, db_1.default)(query, params); | ||
// js dates are ughhh | ||
const params = [eventID, activity, utils_1.default.getDate(), duration]; | ||
const params = [eventID, activity, utils_1.default.getDateStr(), duration]; | ||
const resp = yield (0, db_1.default)(query, params); | ||
@@ -331,3 +331,3 @@ if (resp.err) { | ||
console.log("date to parse: ", targetDurationString); | ||
const seconds = utils_1.default.getDate(targetDurationString); | ||
const seconds = utils_1.default.getDateStr(targetDurationString); | ||
console.log("seconds: ", seconds); | ||
@@ -350,3 +350,3 @@ const params = [activity, seconds]; | ||
// @ts-ignore | ||
const durationTime = utils_1.default.secToTime((_b = resp.data[0].duration) !== null && _b !== void 0 ? _b : 0); | ||
const durationTime = utils_1.default.secToTimeStr((_b = resp.data[0].duration) !== null && _b !== void 0 ? _b : 0); | ||
return { | ||
@@ -369,25 +369,34 @@ err: false, | ||
} | ||
const year = new Date(resp.data[0].date).getFullYear(); | ||
const cal = utils_1.default.generateCalendar(year); | ||
const monthNames = Object.keys(cal); | ||
let previousMonthNumber = undefined; | ||
const firstEventDate = utils_1.default.getDateObj(resp.data[0].date); | ||
const cal = utils_1.default.generateCalendar({ | ||
year: firstEventDate.year, | ||
month: firstEventDate.month, | ||
}); | ||
// console.log({ cal }) | ||
resp.data.forEach((event, index, arr) => { | ||
const { date, duration } = event; | ||
const durationHours = event.duration / 60 / 60; | ||
const eventMonth = new Date(date).getMonth(); | ||
const eventDay = new Date(date).getDate(); | ||
// console.log(eventMonth, monthNames[eventMonth], cal[monthNames[eventMonth]]); | ||
// console.log(eventDay, cal[monthNames[eventMonth]].days[eventDay - 1]); | ||
cal[monthNames[eventMonth]].duration += durationHours; | ||
cal[monthNames[eventMonth]].days[eventDay - 1].hours += durationHours; | ||
const isNextMonth = eventMonth !== previousMonthNumber; | ||
const eventMonthNumber = new Date(event.date).getMonth() + 1; | ||
const eventDayNumber = new Date(event.date).getDate(); | ||
const eventMonthName = utils_1.default.getMonthName(eventMonthNumber); | ||
// console.log(eventMonthNumber, eventDayNumber, eventMonthName); | ||
// console.log({ | ||
// monthNumber: eventMonthNumber, | ||
// monthName: eventMonthName, | ||
// availableMonths: Object.keys(cal), | ||
// dayNumber: eventDayNumber, | ||
// dayInx: eventDayNumber - 1, | ||
// daysCount: cal[eventMonthName].days.length | ||
// }) | ||
// increment durations | ||
cal[eventMonthName].duration += durationHours; | ||
cal[eventMonthName].days[eventDayNumber - 1].hours += durationHours; | ||
// calculate total and avg | ||
const isLastEvent = index == arr.length - 1; | ||
if (previousMonthNumber !== undefined && (isNextMonth || isLastEvent)) { | ||
cal[monthNames[previousMonthNumber]].fullDate = | ||
`${year}-${previousMonthNumber + 1}-${eventDay}`; | ||
const hoursPerDay = cal[monthNames[previousMonthNumber]].duration / | ||
cal[monthNames[previousMonthNumber]].days.length; | ||
cal[monthNames[previousMonthNumber]].hoursPerDay = hoursPerDay; | ||
const isEndOfMonth = cal[eventMonthName].days.length == eventDayNumber; | ||
if (isEndOfMonth && isLastEvent) { | ||
cal[eventMonthName].fullDate = | ||
`${firstEventDate.year}-${eventMonthNumber}`; | ||
cal[eventMonthName].hoursPerDay = | ||
cal[eventMonthName].duration / cal[eventMonthName].days.length; | ||
} | ||
previousMonthNumber = eventMonth; | ||
}); | ||
@@ -429,3 +438,3 @@ return { err: false, data: cal }; | ||
// })(new Date()); | ||
const params = [activity, utils_1.default.getDate(today)]; | ||
const params = [activity, utils_1.default.getDateStr(today)]; | ||
// console.log(query) | ||
@@ -432,0 +441,0 @@ // console.log(params) |
@@ -173,3 +173,3 @@ "use strict"; | ||
} | ||
message = `${activity}: ${utils_1.default.secToTime(resp.data.duration)}`; | ||
message = `${activity}: ${utils_1.default.secToTimeStr(resp.data.duration)}`; | ||
} | ||
@@ -185,3 +185,3 @@ else if (!request.args[0] || | ||
// console.log(duration); | ||
message = `${activity}: ${utils_1.default.secToTime(duration)}`; | ||
message = `${activity}: ${utils_1.default.secToTimeStr(duration)}`; | ||
} | ||
@@ -208,3 +208,3 @@ } | ||
const [monthName, monthData] = month; | ||
data += `\n${monthName}: ${utils_1.default.secToTime(monthData.duration * 60 * 60)} | ${monthData.hoursPerDay.toFixed(2)} hours per day`; | ||
data += `\n${monthName}: ${utils_1.default.secToTimeStr(monthData.duration * 60 * 60)} | ${monthData.hoursPerDay.toFixed(2)} hours per day`; | ||
if (monthData.duration > 0) { | ||
@@ -320,3 +320,3 @@ monthData.days.forEach((day, index) => { | ||
// console.log(duration); | ||
message = `${activity}: ${utils_1.default.secToTime(duration)}`; | ||
message = `${activity}: ${utils_1.default.secToTimeStr(duration)}`; | ||
} | ||
@@ -323,0 +323,0 @@ } |
@@ -55,3 +55,3 @@ "use strict"; | ||
// seconds to time format | ||
const secToTime = (value) => { | ||
const secToTimeStr = (value) => { | ||
var sec_num = parseInt(value.toString(), 10); // don't forget the second param | ||
@@ -82,3 +82,3 @@ const hours = Math.floor(sec_num / 3600); | ||
}; | ||
const getDate = (dateStr) => { | ||
const getDateObj = (dateStr) => { | ||
let date; | ||
@@ -99,2 +99,6 @@ if (dateStr) { | ||
}; | ||
return dateTimeProps; | ||
}; | ||
const getDateStr = (dateStr) => { | ||
const dateTimeProps = getDateObj(dateStr); | ||
Object.keys(dateTimeProps).forEach((propKey) => { | ||
@@ -112,9 +116,13 @@ let value = dateTimeProps[propKey]; | ||
} | ||
fs_1.default.writeFileSync(vars_1.default.logsOutput, `${getDate()} | ${type} | ${message}`); | ||
fs_1.default.writeFileSync(vars_1.default.logsOutput, `${getDateStr()} | ${type} | ${message}`); | ||
}; | ||
function generateCalendar(year) { | ||
function generateCalendar(start) { | ||
const calendar = {}; | ||
for (let month = 0; month < 12; month++) { | ||
const lastDay = new Date(year, month + 1, 0).getDate(); | ||
const monthName = new Date(year, month).toLocaleString("default", { month: "long" }); | ||
for (let monthNumber = start.month; monthNumber <= 12; monthNumber++) { | ||
let lastDay = new Date(start.year, monthNumber, 0).getDate(); | ||
const monthName = new Date(start.year, monthNumber - 1).toLocaleString("default", { month: "long" }); | ||
const currentMonthNumber = new Date().getMonth() + 1; | ||
if (currentMonthNumber == monthNumber) { | ||
lastDay = new Date().getDate(); | ||
} | ||
calendar[monthName] = { | ||
@@ -126,5 +134,15 @@ duration: 0, | ||
}; | ||
if (currentMonthNumber == monthNumber) { | ||
break; | ||
} | ||
} | ||
return calendar; | ||
} | ||
function getMonthName(monthNumber) { | ||
// Date takes index | ||
const name = new Date(2000, monthNumber - 1).toLocaleString("default", { | ||
month: "long", | ||
}); | ||
return name; | ||
} | ||
exports.default = { | ||
@@ -135,8 +153,10 @@ notify, | ||
sleep, | ||
secToTime, | ||
secToTimeStr, | ||
timeToSec, | ||
getDate, | ||
getDateStr, | ||
getDateObj, | ||
log, | ||
debug, | ||
generateCalendar, | ||
getMonthName, | ||
}; |
{ | ||
"name": "clockify", | ||
"version": "0.10.6", | ||
"version": "0.11.6", | ||
"description": "A time tracker to make sure that you really spent the time you think you spent working, studying, etc.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106461
1189