-
Notifications
You must be signed in to change notification settings - Fork 0
/
overview.js
29 lines (26 loc) · 1.03 KB
/
overview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {
determineDateForEndOfYesterday, generateEverhourTimeEntries,
groupTimeEntries,
parseToggleArgs,
retrieveTimeEntries,
sortTimeEntryGroups,
} from './lib.js'
const { from, projectID } = parseToggleArgs()
const to = determineDateForEndOfYesterday()
let timeEntries = await retrieveTimeEntries(from, to, projectID)
timeEntries = timeEntries.filter(timeEntry => timeEntry.duration >= 0)
const timeEntriesPerDay = groupTimeEntries(timeEntries)
sortTimeEntryGroups(timeEntriesPerDay)
console.log(timeEntriesPerDay)
const summary = generateSummary(timeEntriesPerDay)
console.log(summary)
function generateSummary(timeEntriesPerDay) {
return generateEverhourTimeEntries(timeEntriesPerDay).map(({date, time}) => ({date, duration: formatDuration(time)}))
}
function formatDuration(duration) {
const oneHourInSeconds = 60 * 60
const oneMinuteInSeconds = 60
const hours = Math.floor(duration / oneHourInSeconds)
const minutes = Math.ceil((duration - hours * oneHourInSeconds) / oneMinuteInSeconds)
return `${hours}h ${minutes}min`
}