Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit efb6312

Browse files
authored
Merge pull request #7 from attiks/support-weeks-in-time
#6: Support weeks in time parsing
2 parents 70048a5 + 35f34b6 commit efb6312

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

models/time.js

Lines changed: 5 additions & 4 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', 'days', 'hours', 'minutes', 'seconds'];
6-
const regex = /^(?:([-])\s*)?(?:(\d+)d\s*)?(?:(\d+)h\s*)?(?:(\d+)m\s*)?(?:(\d+)s\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*)?$/;
77
const conditionalRegex = /(\[\%([^\>\]]*)\>([^\]]*)\])/ig;
88
const defaultRegex = /(\[\%([^\]]*)\])/ig;
99

@@ -83,7 +83,8 @@ class time {
8383
return (parsed.sign ? -1 : 1) * (parseInt(parsed.seconds)
8484
+ (parseInt(parsed.minutes) * 60)
8585
+ (parseInt(parsed.hours) * 60 * 60)
86-
+ (parseInt(parsed.days) * hoursPerDay * 60 * 60));
86+
+ (parseInt(parsed.days) * hoursPerDay * 60 * 60)
87+
+ (parseInt(parsed.weeks) * 5 * hoursPerDay * 60 * 60));
8788
}
8889

8990
/**
@@ -137,4 +138,4 @@ class time {
137138
}
138139
}
139140

140-
module.exports = time;
141+
module.exports = time;

0 commit comments

Comments
 (0)