-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateUtils.js
35 lines (28 loc) · 920 Bytes
/
DateUtils.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
35
const moment = require('moment-timezone');
class DateUtils {
/**
* Reads date string from moment (in UTC + 14 timezone)
* @param {moment} m Moment object to get date from
* @return {String} Date string
*/
static getDateString(m) {
return m.tz('Pacific/Kiritimati').format('YYYY-MM-DD');
}
static getTodayString() {
return DateUtils.getDateString(moment());
}
static getNowInTimeZone() {
return moment.tz('Pacific/Kiritimati');
}
static getEpochSeconds(m) {
// .unix() returns timestamp is Epoch seconds
return moment(m).seconds(0).unix();
}
static getDateStartMomentInTimeZone(m) {
return moment(m).tz('Pacific/Kiritimati').hours(0).minutes(0).seconds(0);
}
static getDateStartMomentInUTC(m) {
return moment(m).tz('UTC').hours(0).minutes(0).seconds(0);
}
}
module.exports = DateUtils;