Skip to content

Commit 8ecdf05

Browse files
committed
Fix bugs
1 parent 81e6bbc commit 8ecdf05

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/cookbook/icalendarTimeZones.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,21 @@ class ZonedDateTime {
6969
// Use this method instead of PlainDateTime.prototype.toZonedDateTime() and
7070
// PlainDate.prototype.toZonedDateTime()
7171
static fromPlainDateTime(pdt, timeZone, options) {
72-
if (timeZone.tzid) {
72+
if (Intl.supportedValuesOf('timeZone').includes(timeZone.tzid)) {
7373
const temporalZDT = pdt.toZonedDateTime(timeZone.tzid, options);
7474
return new ZonedDateTime(temporalZDT.epochNanoseconds, timeZone, pdt.calendarId);
7575
}
76-
const icalTime = new ICAL.Time(pdt, timeZone);
76+
const icalTime = new ICAL.Time(
77+
{
78+
year: pdt.year,
79+
month: pdt.month,
80+
day: pdt.day,
81+
hour: pdt.hour,
82+
minute: pdt.minute,
83+
second: pdt.second
84+
},
85+
timeZone
86+
);
7787
const epochSeconds = icalTime.toUnixTime(); // apply disambiguation parameter?
7888
const epochNanoseconds =
7989
BigInt(epochSeconds) * 1000000000n + BigInt(pdt.millisecond * 1e6 + pdt.microsecond * 1e3 + pdt.nanosecond);
@@ -273,7 +283,7 @@ class ZonedDateTime {
273283
if (this.#isIANA) {
274284
return this.#impl.toString(options);
275285
}
276-
throw new Error('not implemented');
286+
return this.toPlainDateTime().toString() + `[UNIMPLEMENTED: custom time zone ${this.#timeZone.tzid}]`;
277287
}
278288

279289
toJSON() {

0 commit comments

Comments
 (0)