Skip to content

Commit d337a53

Browse files
author
James Addison
committedOct 15, 2021
Allow null reference timezone; result timezone will not be implied or assigned unless one is read from a parsed date
1 parent 1f38c0b commit d337a53

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

‎src/results.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dayjs.extend(quarterOfYear);
88

99
export class ReferenceWithTimezone {
1010
readonly instant: Date;
11-
readonly timezoneOffset: number;
11+
readonly timezoneOffset?: number;
1212

1313
constructor(input?: ParsingReference | Date) {
1414
input = input ?? new Date();
@@ -17,7 +17,7 @@ export class ReferenceWithTimezone {
1717
this.timezoneOffset = -input.getTimezoneOffset();
1818
} else {
1919
this.instant = input.instant ?? new Date();
20-
this.timezoneOffset = toTimezoneOffset(input.timezone ?? -this.instant.getTimezoneOffset());
20+
this.timezoneOffset = toTimezoneOffset(input.timezone);
2121
}
2222
}
2323
}
@@ -180,10 +180,14 @@ export class ParsingComponents implements ParsedComponents {
180180
if (fragments["hour"] || fragments["minute"] || fragments["second"]) {
181181
assignSimilarTime(components, date);
182182
assignSimilarDate(components, date);
183-
components.assign("timezoneOffset", -reference.instant.getTimezoneOffset());
183+
if (reference.timezoneOffset !== null) {
184+
components.assign("timezoneOffset", -reference.instant.getTimezoneOffset());
185+
}
184186
} else {
185187
implySimilarTime(components, date);
186-
components.imply("timezoneOffset", -reference.instant.getTimezoneOffset());
188+
if (reference.timezoneOffset !== null) {
189+
components.imply("timezoneOffset", -reference.instant.getTimezoneOffset());
190+
}
187191

188192
if (fragments["d"]) {
189193
components.assign("day", date.date());

‎src/timezone.ts

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ export const TIMEZONE_ABBR_MAP = {
193193
};
194194

195195
export function toTimezoneOffset(timezoneInput: string | number): number {
196+
if (timezoneInput === null) {
197+
return null;
198+
}
199+
196200
if (typeof timezoneInput === "number") {
197201
return timezoneInput;
198202
}

0 commit comments

Comments
 (0)
Please sign in to comment.