Skip to content

Commit 7e238dc

Browse files
Nedgevaraveclassic
authored andcommitted
fix(ts-utils): remove timezone detection from DateFromISODateStringIO
1 parent 2a5be3c commit 7e238dc

File tree

1 file changed

+3
-17
lines changed
  • src/language/typescript/common/bundled

1 file changed

+3
-17
lines changed

src/language/typescript/common/bundled/utils.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,13 @@ const utils = `
99
import { either } from 'fp-ts/lib/Either';
1010
import { Type, failure, success, string as tstring } from 'io-ts';
1111
12-
const getISOTimezoneOffsetString = (offsetMinutes: number): string => {
13-
if (offsetMinutes === 0) {
14-
return 'Z';
15-
}
16-
17-
const absoluteOffsetMinutes = Math.abs(offsetMinutes);
18-
const offsetHours = absoluteOffsetMinutes / 60;
19-
const offsetRestMinutes = absoluteOffsetMinutes % 60;
20-
21-
return \`\${offsetMinutes > 0 ? '-' : '+'}\${offsetHours
22-
.toString()
23-
.padStart(2, '0')}:\${offsetRestMinutes.toString().padStart(2, '0')}\`;
24-
};
25-
2612
export const DateFromISODateStringIO = new Type<Date, string, unknown>(
2713
'DateFromISODateString',
2814
(u): u is Date => u instanceof Date,
2915
(u, c) =>
30-
either.chain(tstring.validate(u, c), s => {
31-
const offset = new Date().getTimezoneOffset();
32-
const d = new Date(\`\${s}T00:00:00\${getISOTimezoneOffsetString(offset)}\`);
16+
either.chain(tstring.validate(u, c), dateString => {
17+
const [year, calendarMonth, day] = dateString.split('-');
18+
const d = new Date(+year, +calendarMonth - 1, +day);
3319
return isNaN(d.getTime()) ? failure(u, c) : success(d);
3420
}),
3521
a =>

0 commit comments

Comments
 (0)