2
2
# A Hubot script to close time entries for new payment
3
3
#
4
4
# Dependencies:
5
- # "bluebird": "^3.2.1",
6
- # "moment ": "^2.11.2",
7
- # "request-promise ": "^2 .0.0",
8
- # "simple-encryptor": "^1.0.3",
9
- # "toggl-api": "0 .0.4 "
5
+ # "bluebird": "^3.4.6"
6
+ # "indicadoresdeldia ": "^0.0.3"
7
+ # "parse-ms ": "^1 .0.1"
8
+ # "simple-encryptor": "^1.1.0"
9
+ # "toggl-api": "^1 .0.1 "
10
10
#
11
11
# Configuration:
12
12
# TOGGL_CHANNEL
19
19
# Author:
20
20
# lgaticaq
21
21
22
- moment = require " moment "
22
+ parseMs = require " parse-ms "
23
23
TogglClient = require " toggl-api"
24
24
Promise = require " bluebird"
25
25
simpleEncryptor = require " simple-encryptor"
@@ -30,8 +30,16 @@ getClient = (token) ->
30
30
Promise .promisifyAll Object .getPrototypeOf toggl
31
31
toggl
32
32
33
+ pad = (n , width , z = " 0" ) ->
34
+ n = n + " "
35
+ if n .length >= width
36
+ return n
37
+ else
38
+ return new Array (width - n .length + 1 ).join (z) + n
39
+
33
40
parseDuration = (duration ) ->
34
- return moment .utc (duration * 1000 ).format (" HH:mm:ss" )
41
+ ms = parseMs (duration * 1000 )
42
+ return " #{ pad (ms .hours , 2 )} :#{ pad (ms .minutes , 2 )} :#{ pad (ms .seconds , 2 )} "
35
43
36
44
processTimeEntries = (timeEntries , amount , price ) ->
37
45
new Promise (resolve , reject ) ->
@@ -93,8 +101,10 @@ module.exports = (robot) ->
93
101
res .send " Processing time entries..."
94
102
tags = [" Pagado" ]
95
103
action = " add"
96
- end = moment ().toISOString ()
97
- start = moment ().subtract (1 , " years" ).toISOString ()
104
+ today = new Date ()
105
+ end = today .toISOString ()
106
+ today .setFullYear (today .getFullYear () - 1 )
107
+ start = today .toISOString ()
98
108
user = robot .brain .userForName res .message .user .name
99
109
encryptor = simpleEncryptor secret
100
110
message = " "
0 commit comments