-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
27 lines (22 loc) · 705 Bytes
/
utils.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
// @flow
const MS_IN_HR = 3600 * 1000;
const MS_IN_DAY = 24 * MS_IN_HR;
const UTC_TO_EST = 5 * MS_IN_HR;
export function isAlphabetCharacter(character) {
return character.length === 1 && character.match(/[a-z]/i);
}
export function getCharacterDiffCount(string1, string2) {
let diffs = 0;
string2.split('').forEach((character, index) => {
if (character !== string1.charAt(index))
diffs += 1;
});
return diffs;
}
export function getNumDaysSinceEpoch() {
return Math.floor((Date.now() - UTC_TO_EST) / MS_IN_DAY);
}
export function getDateStringFromDaysSinceEpoch(daysSinceEpoch) {
const date = new Date(daysSinceEpoch * MS_IN_DAY);
return date.toLocaleDateString();
}