forked from danibram/time-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.js
More file actions
46 lines (37 loc) · 1.41 KB
/
Copy pathOutput.js
File metadata and controls
46 lines (37 loc) · 1.41 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import moment from 'moment'
import Table from 'cli-table'
import {humanParseDiff, recognizeModifierTiming, calcRate} from './Utils'
export const sumarize = function(search, tasks, rate, full) {
let table = new Table({
head: ['Duration', 'Dates', 'Task'],
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
colAligns: ['right', 'center', 'left'],
style: { head: ['green'] }
});
let total = 0
let head= `Search: ${search} \n`
tasks.map((task, index)=>{
let duration = moment(task.task.stop).diff(moment(task.task.start), 'seconds')
total += duration
let outputDuration = humanParseDiff(duration)
let name = task.name
let startTime = moment(task.task.start).format('DD/MM/YYYY')
let stopTime = moment(task.task.stop).format('DD/MM/YYYY')
if (startTime !== stopTime){
startTime = moment(task.task.start).format('DD/MM') + '|' + moment(task.task.stop).format('DD/MM YYYY')
}
table.push([outputDuration, startTime, name])
})
console.log(table.toString());
if (full){
let table2 = new Table()
table2.push(
{ 'Search': ['\"' + search + '\"'] },
{ 'Total time': [humanParseDiff(total)] }
)
if (rate){
table2.push({ 'Rate': [calcRate(rate, total)] })
}
console.log(table2.toString());
}
}