forked from UncannyBingo/easy-peasy-slash-command-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
34 lines (27 loc) · 978 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const moment = require('moment');
/** TimeRemain
*
* @param {object} timeStart - Date/time of start time.
* @param {object} timeNow - Date/time of now.
*
* @return {string} Time remaining in HH:mm format.
*
*/
const timeRemain = (timeStart, timeNow) => {
const timeMandatory = 8 * 60 * 60; // 8 hours in seconds
// NOTE: unix time returns seconds, duration expects milliseconds
return moment.duration((moment(timeStart).unix() + timeMandatory - moment(timeNow).unix()) * 1000).format('HH:mm');
};
/** TimeDuration
*
* @param {object} timeStart - Date/time of start time.
* @param {object} timeNow - Date/time of now.
*
* @return {string} Time duration in HH:mm format.
*
*/
const timeDuration = (timeStart, timeNow) => {
// NOTE: unix time returns seconds, duration expects milliseconds
return moment.duration((moment(timeNow).unix() - moment(timeStart).unix()) * 1000).format('HH:mm');
};
module.exports = { timeRemain, timeDuration };