forked from projecthamster/hamster-shell-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stuff.js
67 lines (56 loc) · 1.56 KB
/
stuff.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function formatDuration(minutes) {
return "%02d:%02d".format((minutes - minutes % 60) / 60, minutes % 60)
}
function formatDurationHuman(minutes) {
let hours = (minutes - minutes % 60) / 60;
let mins = minutes % 60;
let res = ""
if (hours > 0 || mins > 0) {
if (hours > 0)
res += "%dh ".format(hours)
if (mins > 0)
res += "%dmin".format(mins)
} else {
res = "Just started"
}
return res;
}
function formatDurationHours(minutes) {
return new Number(minutes / 60.0).toFixed(1) + "h";
}
function fromDbusFact(fact) {
// converts a fact coming from dbus into a usable object
function UTCToLocal(timestamp) {
// TODO - is this really the way?!
let res = new Date(timestamp)
return new Date(res.setUTCMinutes(res.getUTCMinutes() + res.getTimezoneOffset()));
}
return {
name: fact[4],
startTime: UTCToLocal(fact[1]*1000),
endTime: fact[2] != 0 ? UTCToLocal(fact[2]*1000) : null,
description: fact[3],
activityId: fact[5],
category: fact[6],
tags: fact[7],
date: UTCToLocal(fact[8] * 1000),
delta: Math.floor(fact[9] / 60), // minutes
id: fact[0]
}
};
function fromDbusFacts(facts) {
let res = [];
for each(var fact in facts) {
res.push(fromDbusFact(fact));
}
return res;
};
function parseFactString(input) {
let res = {
"time": null,
"activity": input,
"category": null,
"description": null,
"tags": null,
}
}