Commit b5ab18c6 authored by Ruben Davila's avatar Ruben Davila

Bring changes that were present only in EE.

parent 770a199f
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
* stringifyTime condensed or non-condensed, abbreviateTimelengths) * stringifyTime condensed or non-condensed, abbreviateTimelengths)
* */ * */
class PrettyTime { const utils = window.gl.utils = gl.utils || {};
const prettyTime = utils.prettyTime = {
/* /*
* Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # } * Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # }
* Seconds can be negative or positive, zero or non-zero. * Seconds can be negative or positive, zero or non-zero.
*/ */
static parseSeconds(seconds) { parseSeconds(seconds) {
const DAYS_PER_WEEK = 5; const DAYS_PER_WEEK = 5;
const HOURS_PER_DAY = 8; const HOURS_PER_DAY = 8;
const MINUTES_PER_HOUR = 60; const MINUTES_PER_HOUR = 60;
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
minutes: 1, minutes: 1,
}; };
let unorderedMinutes = PrettyTime.secondsToMinutes(seconds); let unorderedMinutes = prettyTime.secondsToMinutes(seconds);
return _.mapObject(timePeriodConstraints, (minutesPerPeriod) => { return _.mapObject(timePeriodConstraints, (minutesPerPeriod) => {
const periodCount = Math.floor(unorderedMinutes / minutesPerPeriod); const periodCount = Math.floor(unorderedMinutes / minutesPerPeriod);
...@@ -33,35 +33,33 @@ ...@@ -33,35 +33,33 @@
return periodCount; return periodCount;
}); });
} },
/* /*
* Accepts a timeObject and returns a condensed string representation of it * Accepts a timeObject and returns a condensed string representation of it
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included. * (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
*/ */
static stringifyTime(timeObject) { stringifyTime(timeObject) {
const reducedTime = _.reduce(timeObject, (memo, unitValue, unitName) => { const reducedTime = _.reduce(timeObject, (memo, unitValue, unitName) => {
const isNonZero = !!unitValue; const isNonZero = !!unitValue;
return isNonZero ? `${memo} ${unitValue}${unitName.charAt(0)}` : memo; return isNonZero ? `${memo} ${unitValue}${unitName.charAt(0)}` : memo;
}, '').trim(); }, '').trim();
return reducedTime.length ? reducedTime : '0m'; return reducedTime.length ? reducedTime : '0m';
} },
/* /*
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns * Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* the first non-zero unit/value pair. * the first non-zero unit/value pair.
*/ */
static abbreviateTime(timeStr) { abbreviateTime(timeStr) {
return timeStr.split(' ') return timeStr.split(' ')
.filter(unitStr => unitStr.charAt(0) !== '0')[0]; .filter(unitStr => unitStr.charAt(0) !== '0')[0];
} },
static secondsToMinutes(seconds) { secondsToMinutes(seconds) {
return Math.abs(seconds / 60); return Math.abs(seconds / 60);
} },
} };
gl.PrettyTime = PrettyTime;
})(window.gl || (window.gl = {})); })(window.gl || (window.gl = {}));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment