Skip to content

Commit 1411bc5

Browse files
committed
add parsing of dates. closes kriskbx#39
1 parent dda7631 commit 1411bc5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/models/hasTimes.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const moment = require('moment');
44
const Base = require('./base');
55
const Time = require('./time');
66

7-
const regex = /added (.*) of time spent/i;
8-
const subRegex = /subtracted (.*) of time spent/i;
7+
const regex = /added (.*) of time spent(?: at (.*))?/i;
8+
const subRegex = /subtracted (.*) of time spent(?: at (.*))?/i;
99
const removeRegex = /Removed time spent/i;
1010

1111
/**
@@ -70,17 +70,20 @@ class hasTimes extends Base {
7070
let promise = this.parallel(this.notes, (note, done) => {
7171
let created = moment(note.created_at), match, subMatch;
7272

73-
7473
if ( //
7574
// filter out user notes
7675
!note.system ||
7776
// filter out notes that are no time things
7877
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !removeRegex.exec(note.body)
7978
) return done();
8079

80+
// change created date when explicitly defined
81+
if(match && match[2]) created = moment(match[2]);
82+
if(subMatch && subMatch[2]) created = moment(subMatch[2]);
83+
8184
// create a time string and a time object
8285
let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent, this.config.get('hoursPerDay'))}`);
83-
let time = new Time(timeString, note, this, this.config);
86+
let time = new Time(timeString, created, note, this, this.config);
8487

8588
// add to total time spent
8689
totalTimeSpent += time.seconds;
@@ -124,7 +127,7 @@ class hasTimes extends Base {
124127
let difference = this.data.time_stats.total_time_spent - totalTimeSpent,
125128
note = Object.assign({noteable_type: this._typeSingular}, this.data);
126129

127-
times.unshift(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), note, this, this.config));
130+
times.unshift(new Time(Time.toHumanReadable(difference, null, this.config.get('hoursPerDay')), note, this, this.config));
128131

129132
resolve();
130133
}));

src/models/time.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class time {
2424
* @param parent
2525
* @param config
2626
*/
27-
constructor(timeString, note, parent, config) {
27+
constructor(timeString, date = null, note, parent, config) {
2828
this.data = note;
29+
this._date = date;
2930
this.parent = parent;
3031
this.config = config;
3132
this.seconds = time.parse(timeString, this._hoursPerDay);
@@ -43,7 +44,7 @@ class time {
4344
}
4445

4546
get date() {
46-
return moment(this.data.created_at);
47+
return this._date ? moment(this._date) : moment(this.data.created_at);
4748
}
4849

4950
get type() {

0 commit comments

Comments
 (0)