Skip to content

Commit c3d93bc

Browse files
committed
Add months parsing
1 parent a665dbf commit c3d93bc

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ showWithoutTimes: true
552552
# defaults to 8
553553
hoursPerDay: 8
554554

555+
# Days per week
556+
# defaults to 5
557+
daysPerWeek: 5
558+
559+
# Weeks per month
560+
# defaults to 4
561+
weeksPerMonth: 4
562+
555563
# Include the given columns in the issue table
556564
# See --issue_columns option for more information
557565
# defaults to iid, title, spent, total_estimate

src/include/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const defaults = {
2020
closed: false,
2121
milestone: false,
2222
hoursPerDay: 8,
23+
daysPerWeek: 5,
24+
weeksPerMonth: 4,
2325
issueColumns: ['iid', 'title', 'spent', 'total_estimate'],
2426
mergeRequestColumns: ['iid', 'title', 'spent', 'total_estimate'],
2527
recordColumns: ['user', 'date', 'type', 'iid', 'time'],

src/models/time.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const _ = require('underscore');
22
const moment = require('moment');
33

44
const defaultTimeFormat = '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]';
5-
const mappings = ['complete', 'sign', 'weeks', 'days', 'hours', 'minutes', 'seconds'];
6-
const regex = /^(?:([-])\s*)?(?:(\d+)w\s*)?(?:(\d+)d\s*)?(?:(\d+)h\s*)?(?:(\d+)m\s*)?(?:(\d+)s\s*)?$/;
5+
const mappings = ['complete', 'sign', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'];
6+
const regex = /^(?:([-])\s*)?(?:(\d+)mo\s*)?(?:(\d+)w\s*)?(?:(\d+)d\s*)?(?:(\d+)h\s*)?(?:(\d+)m\s*)?(?:(\d+)s\s*)?$/;
77
const conditionalRegex = /(\[\%([^\>\]]*)\>([^\]]*)\])/ig;
88
const roundedRegex = /(\[\%([^\>\]]*)\:([^\]]*)\])/ig;
99
const conditionalSimpleRegex = /([0-9]*)\>(.*)/ig;
@@ -29,7 +29,7 @@ class time {
2929
this._date = date;
3030
this.parent = parent;
3131
this.config = config;
32-
this.seconds = time.parse(timeString, this._hoursPerDay);
32+
this.seconds = time.parse(timeString, this._hoursPerDay, this._daysPerWeek, this._weeksPerMonth);
3333
}
3434

3535
/*
@@ -71,13 +71,23 @@ class time {
7171
return this.config && this.config.get('hoursPerDay') ? parseInt(this.config.get('hoursPerDay')) : 8;
7272
}
7373

74+
get _daysPerWeek() {
75+
return this.config && this.config.get('daysPerWeek') ? parseInt(this.config.get('daysPerWeek')) : 5;
76+
}
77+
78+
get _weeksPerMonth() {
79+
return this.config && this.config.get('weeksPerMonth') ? parseInt(this.config.get('weeksPerMonth')) : 4;
80+
}
81+
7482
/**
7583
* parse human readable to seconds
7684
* @param string
7785
* @param hoursPerDay
86+
* @param daysPerWeek
87+
* @param weeksPerMonth
7888
* @returns {*}
7989
*/
80-
static parse(string, hoursPerDay = 8) {
90+
static parse(string, hoursPerDay = 8, daysPerWeek = 5, weeksPerMonth = 4) {
8191
let match, parsed;
8292

8393
if ((match = regex.exec(string)) === null) return false;
@@ -87,7 +97,8 @@ class time {
8797
+ (parseInt(parsed.minutes) * 60)
8898
+ (parseInt(parsed.hours) * 60 * 60)
8999
+ (parseInt(parsed.days) * hoursPerDay * 60 * 60)
90-
+ (parseInt(parsed.weeks) * 5 * hoursPerDay * 60 * 60));
100+
+ (parseInt(parsed.weeks) * daysPerWeek * hoursPerDay * 60 * 60)
101+
+ (parseInt(parsed.months) * weeksPerMonth * daysPerWeek * hoursPerDay * 60 * 60));
91102
}
92103

93104
/**

0 commit comments

Comments
 (0)