|
1 | 1 | import { changeCase, padStart, padEnd } from './underscore'
|
2 | 2 |
|
3 |
| -export const timezoneOffset = new Date().getTimezoneOffset() |
4 |
| -const ISO8601_TIMEZONE_PATTERN = /([zZ]|([+-])(\d{2}):(\d{2}))$/ |
5 | 3 | const rFormat = /%([-_0^#:]+)?(\d+)?([EO])?(.)/
|
6 | 4 | const monthNames = [
|
7 | 5 | 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
|
@@ -127,10 +125,10 @@ const formatCodes = {
|
127 | 125 | y: (d: Date) => d.getFullYear().toString().substring(2, 4),
|
128 | 126 | Y: (d: Date) => d.getFullYear(),
|
129 | 127 | z: (d: Date, opts: FormatOptions) => {
|
130 |
| - const nOffset = Math.abs(timezoneOffset) |
| 128 | + const nOffset = Math.abs(d.getTimezoneOffset()) |
131 | 129 | const h = Math.floor(nOffset / 60)
|
132 | 130 | const m = nOffset % 60
|
133 |
| - return (timezoneOffset > 0 ? '-' : '+') + |
| 131 | + return (d.getTimezoneOffset() > 0 ? '-' : '+') + |
134 | 132 | padStart(h, 2, '0') +
|
135 | 133 | (opts.flags[':'] ? ':' : '') +
|
136 | 134 | padStart(m, 2, '0')
|
@@ -169,31 +167,3 @@ function format (d: Date, match: RegExpExecArray) {
|
169 | 167 | if (flags['-']) padWidth = 0
|
170 | 168 | return padStart(ret, padWidth, padChar)
|
171 | 169 | }
|
172 |
| - |
173 |
| -/** |
174 |
| - * Create a Date object fixed to it's declared Timezone. Both |
175 |
| - * - 2021-08-06T02:29:00.000Z and |
176 |
| - * - 2021-08-06T02:29:00.000+08:00 |
177 |
| - * will always be displayed as |
178 |
| - * - 2021-08-06 02:29:00 |
179 |
| - * regardless timezoneOffset in JavaScript realm |
180 |
| - * |
181 |
| - * The implementation hack: |
182 |
| - * Instead of calling `.getMonth()`/`.getUTCMonth()` respect to `preserveTimezones`, |
183 |
| - * we create a different Date to trick strftime, it's both simpler and more performant. |
184 |
| - * Given that a template is expected to be parsed fewer times than rendered. |
185 |
| - */ |
186 |
| -export function createDateFixedToTimezone (dateString: string) { |
187 |
| - const m = dateString.match(ISO8601_TIMEZONE_PATTERN) |
188 |
| - // representing a UTC datetime |
189 |
| - if (m && m[1] === 'Z') { |
190 |
| - return new Date(+new Date(dateString) + timezoneOffset * 60000) |
191 |
| - } |
192 |
| - // has a timezone specified |
193 |
| - if (m && m[2] && m[3] && m[4]) { |
194 |
| - const [, , sign, hours, minutes] = m |
195 |
| - const delta = (sign === '+' ? 1 : -1) * (parseInt(hours, 10) * 60 + parseInt(minutes, 10)) |
196 |
| - return new Date(+new Date(dateString) + (timezoneOffset + delta) * 60000) |
197 |
| - } |
198 |
| - return new Date(dateString) |
199 |
| -} |
0 commit comments