-
Notifications
You must be signed in to change notification settings - Fork 0
/
UTCTimezone.ts
86 lines (71 loc) · 1.61 KB
/
UTCTimezone.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Timezone } from './Timezone'
import { DatePartResponse } from './types'
class UtcTimezone extends Timezone {
constructor() {
super('UTC')
}
makeDate(
year: number,
monthIndex: number,
day: number = 1,
hours: number = 0,
minutes: number = 0,
seconds: number = 0,
milliseconds: number = 0
): Date {
return new Date(
Date.UTC(year, monthIndex, day, hours, minutes, seconds, milliseconds)
)
}
dateParts(date: Date): DatePartResponse {
return {
year: date.getUTCFullYear(),
monthIndex: date.getUTCMonth(),
weekday: date.getUTCDay(),
day: date.getUTCDate(),
hours: date.getUTCHours(),
minutes: date.getUTCMinutes(),
seconds: date.getUTCSeconds(),
milliseconds: date.getUTCMilliseconds()
}
}
offset(date: Date): number {
return 0
}
toISOString(date: Date): string {
return date.toISOString()
}
year(date: Date): number {
return date.getUTCFullYear()
}
monthIndex(date: Date): number {
return date.getUTCMonth()
}
weekday(date: Date): number {
return date.getUTCDay()
}
day(date: Date): number {
return date.getUTCDate()
}
hours(date: Date): number {
return date.getUTCHours()
}
minutes(date: Date): number {
return date.getUTCMinutes()
}
seconds(date: Date): number {
return date.getUTCSeconds()
}
milliseconds(date: Date): number {
return date.getUTCMilliseconds()
}
isDaylightSavings(date: Date): boolean {
return false
}
}
/**
* The timezone for UTC.
*
* @category Timezone
*/
export const tzUtc = new UtcTimezone()