Skip to content

Commit dda7631

Browse files
committed
add timezones
1 parent 001ba60 commit dda7631

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"markdown-table": "^1.1.0",
3939
"mdpdf": "^1.5.1",
4040
"moment": "^2.18.1",
41+
"moment-timezone": "^0.5.16",
4142
"node-spinner": "^0.0.4",
4243
"open": "^0.0.5",
4344
"progress": "^2.0.0",

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/home/kriskbx/data/Keys/ssh/github_rsa"# ![gtt](https://raw.githubusercontent.com/kriskbx/gitlab-time-tracker/master/preview/icon.png) gtt
1+
# ![gtt](https://raw.githubusercontent.com/kriskbx/gitlab-time-tracker/master/preview/icon.png) gtt
22

33
[![npm](https://img.shields.io/npm/dt/gitlab-time-tracker.svg?style=flat-square)](https://www.npmjs.com/package/gitlab-time-tracker)
44
[![npm](https://img.shields.io/npm/v/gitlab-time-tracker.svg?style=flat-square)](https://www.npmjs.com/package/gitlab-time-tracker)
@@ -216,6 +216,7 @@ gtt cancel
216216
```shell
217217
gtt log
218218
```
219+
Note: gtt log uses UTC as default timezone. If you want to display the times in a different timezone, make sure to use `timezone: "Europe/Berlin"` in your config.
219220

220221
**Edit a local time record by the given id:**
221222

@@ -600,6 +601,10 @@ timeFormat:
600601
merge_requests: "[%sign][%hours_overall]"
601602
records: "[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]"
602603

604+
# Change your timezone
605+
# default: UTC
606+
timezone: "Europe/Berlin"
607+
603608
# Output type
604609
# Available: csv, table, markdown, pdf
605610
# defaults to table

src/gtt-log.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const _ = require('underscore');
22
const program = require('commander');
33
const colors = require('colors');
4-
const moment = require('moment');
4+
const moment = require('moment-timezone');
55

66
const Config = require('./include/file-config');
77
const Cli = require('./include/cli');
@@ -31,10 +31,10 @@ tasks.log()
3131

3232
console.log(`${moment(date).format('MMMM Do YYYY')} (${toHumanReadable(times[date])})`.green);
3333
frames[date]
34-
.sort((a, b) => moment(a.start).isBefore(moment(b.start)) ? -1 : 1)
34+
.sort((a, b) => a.start.isBefore(b.start) ? -1 : 1)
3535
.forEach(frame => {
3636
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
37-
console.log(` ${frame.id} ${moment(frame.start).format('HH:mm').green} to ${moment(frame.stop).format('HH:mm').green}\t${toHumanReadable(frame.duration)}\t\t${frame.project.magenta}\t\t${issue}`)
37+
console.log(` ${frame.id} ${frame.start.clone().format('HH:mm').green} to ${frame.stop.clone().format('HH:mm').green}\t${toHumanReadable(frame.duration)}\t\t${frame.project.magenta}\t\t${issue}`)
3838
});
3939
});
4040
}

src/include/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const defaults = {
3636
noWarnings: false,
3737
quiet: false,
3838
showWithoutTimes: false,
39+
timezone: "UTC",
3940
_perPage: 100,
4041
_parallel: 10,
4142
_verbose: false,

src/include/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class tasks {
156156
new FrameCollection(this.config)
157157
.forEach((frame, done) => {
158158
if (frame.stop === false) return done();
159-
let date = moment(frame.start).format('YYYY-MM-DD');
159+
let date = frame.date.format('YYYY-MM-DD');
160160

161161
if (!frames[date]) frames[date] = [];
162162
if (!times[date]) times[date] = 0;

src/models/frame.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const moment = require('moment');
3+
const moment = require('moment-timezone');
44
const Hashids = require('hashids');
55
const hashids = new Hashids();
66

@@ -20,18 +20,20 @@ class frame {
2020
this.resource.new = true;
2121

2222
this.id = frame.generateId();
23-
this.start = false;
24-
this.stop = false;
23+
this._start = false;
24+
this._stop = false;
25+
this.timezone = config.get('timezone');
2526
this.notes = [];
2627
}
2728

2829
static fromJson(config, json) {
2930
let frame = new this(config, json.resource.id, json.resource.type);
3031
frame.project = json.project;
3132
frame.id = json.id;
32-
frame.start = json.start;
33-
frame.stop = json.stop;
33+
frame._start = json.start;
34+
frame._stop = json.stop;
3435
frame.notes = json.notes;
36+
frame.timezone = json.timezone;
3537

3638
return frame;
3739
}
@@ -41,19 +43,26 @@ class frame {
4143
}
4244

4345
startMe() {
44-
this.start = new Date();
46+
this._start = this._getCurrentDate();
4547
this.write();
4648

4749
return this;
4850
}
4951

5052
stopMe() {
51-
this.stop = new Date();
53+
this._stop = this._getCurrentDate();
5254
this.write();
5355

5456
return this;
5557
}
5658

59+
_getCurrentDate() {
60+
if(this.timezone)
61+
return moment().tz(this.timezone).format();
62+
63+
return moment();
64+
}
65+
5766
/**
5867
* assert file exists
5968
*/
@@ -71,8 +80,9 @@ class frame {
7180
project: this.project,
7281
resource: this.resource,
7382
notes: this.notes,
74-
start: this.start,
75-
stop: this.stop
83+
start: this._start,
84+
stop: this._stop,
85+
timezone: this.timezone
7686
}, null, "\t"));
7787
}
7888

@@ -84,6 +94,18 @@ class frame {
8494
return moment(this.stop).diff(this.start) / 1000;
8595
}
8696

97+
get date() {
98+
return this.start;
99+
}
100+
101+
get start() {
102+
return this.timezone ? moment(this._start).tz(this.timezone) : moment(this._start);
103+
}
104+
105+
get stop() {
106+
return this.timezone ? moment(this._stop).tz(this.timezone) : moment(this._stop);
107+
}
108+
87109
/**
88110
* generate a unique id
89111
* @returns {number}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,16 @@ mocha@^3.5.0:
12711271
mkdirp "0.5.1"
12721272
supports-color "3.1.2"
12731273

1274+
moment-timezone@^0.5.16:
1275+
version "0.5.16"
1276+
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.16.tgz#661717d5f55b4d2c2e002262d726c83785192a5a"
1277+
dependencies:
1278+
moment ">= 2.9.0"
1279+
1280+
"moment@>= 2.9.0":
1281+
version "2.22.1"
1282+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.1.tgz#529a2e9bf973f259c9643d237fda84de3a26e8ad"
1283+
12741284
moment@^2.18.1:
12751285
version "2.18.1"
12761286
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

0 commit comments

Comments
 (0)