-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ts
58 lines (57 loc) · 1.37 KB
/
helpers.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const helpers = {
// @ts-ignore
friendlyDate: function (a) {
var months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
var days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var day = days[a.getDay()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time_friendly = this.getTime(a);
var time = {
day: day,
date: date,
month: month,
year: year,
hour: hour,
min: min,
sec: sec,
time_friendly: time_friendly,
};
return time;
},
// @ts-ignore
getTime: function (date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ampm;
return strTime;
},
// @ts-ignore
stringToFriendlyDate: function (date_string) {
const date = helpers.friendlyDate(new Date(date_string));
const friendly_date = `${date.month} ${date.date}, ${date.year}`;
return friendly_date;
},
};
export default helpers;