Skip to content

Commit f3f8a99

Browse files
12wrigjaptomato
andauthored
Co-authored-by: Philip Chimento <[email protected]>
1 parent b8138dc commit f3f8a99

File tree

7 files changed

+63
-38
lines changed

7 files changed

+63
-38
lines changed

lib/ecmascript.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ function ParseTemporalTimeString(isoString: string) {
391391
nanosecond = ToInteger(fraction.slice(6, 9));
392392
calendar = match[15];
393393
} else {
394-
({ hour, minute, second, millisecond, microsecond, nanosecond, calendar } = ParseISODateTime(isoString, {
394+
let z;
395+
({ hour, minute, second, millisecond, microsecond, nanosecond, calendar, z } = ParseISODateTime(isoString, {
395396
zoneRequired: false
396397
}));
398+
if (z) throw new RangeError('Z designator not supported for PlainTime');
397399
}
398400
return { hour, minute, second, millisecond, microsecond, nanosecond, calendar };
399401
}
@@ -408,7 +410,9 @@ function ParseTemporalYearMonthString(isoString: string) {
408410
month = ToInteger(match[2]);
409411
calendar = match[3];
410412
} else {
411-
({ year, month, calendar, day: referenceISODay } = ParseISODateTime(isoString, { zoneRequired: false }));
413+
let z;
414+
({ year, month, calendar, day: referenceISODay, z } = ParseISODateTime(isoString, { zoneRequired: false }));
415+
if (z) throw new RangeError('Z designator not supported for PlainYearMonth');
412416
}
413417
return { year, month, calendar, referenceISODay };
414418
}
@@ -420,7 +424,9 @@ function ParseTemporalMonthDayString(isoString: string) {
420424
month = ToInteger(match[1]);
421425
day = ToInteger(match[2]);
422426
} else {
423-
({ month, day, calendar, year: referenceISOYear } = ParseISODateTime(isoString, { zoneRequired: false }));
427+
let z;
428+
({ month, day, calendar, year: referenceISOYear, z } = ParseISODateTime(isoString, { zoneRequired: false }));
429+
if (z) throw new RangeError('Z designator not supported for PlainMonthDay');
424430
}
425431
return { month, day, calendar, referenceISOYear };
426432
}
@@ -1262,7 +1268,8 @@ export function ToTemporalDate(
12621268
return DateFromFields(calendar, fields, options);
12631269
}
12641270
ToTemporalOverflow(options); // validate and ignore
1265-
const { year, month, day, calendar } = ParseTemporalDateString(ToString(item));
1271+
const { year, month, day, calendar, z } = ParseTemporalDateString(ToString(item));
1272+
if (z) throw new RangeError('Z designator not supported for PlainDate');
12661273
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
12671274
return new TemporalPlainDate(year, month, day, calendar); // include validation
12681275
}
@@ -1349,8 +1356,10 @@ export function ToTemporalDateTime(
13491356
));
13501357
} else {
13511358
ToTemporalOverflow(options); // validate and ignore
1352-
({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar } =
1359+
let z;
1360+
({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar, z } =
13531361
ParseTemporalDateTimeString(ToString(item)));
1362+
if (z) throw new RangeError('Z designator not supported for PlainDateTime');
13541363
RejectDateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
13551364
if (calendar === undefined) calendar = GetISO8601Calendar();
13561365
calendar = ToTemporalCalendar(calendar);

test/expected-failures.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ built-ins/Temporal/Duration/prototype/total/options-wrong-type.js
99

1010
# https://github.com/tc39/test262/pull/3316
1111
intl402/Temporal/TimeZone/from/argument-invalid.js
12+
13+
# Waiting on submitting tests for https://github.com/tc39/proposal-temporal/pull/1874
14+
built-ins/Temporal/PlainMonthDay/from/fields-string.js

test/plaindatetime.mjs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ describe('DateTime', () => {
12621262
equal(`${dt.round({ smallestUnit: 'second' })}`, '1976-11-18T14:23:30');
12631263
});
12641264
it('rounding down is towards the Big Bang, not towards 1 BCE', () => {
1265-
const dt2 = PlainDateTime.from('-000099-12-15T12:00:00.5Z');
1265+
const dt2 = PlainDateTime.from('-000099-12-15T12:00:00.5');
12661266
const smallestUnit = 'second';
12671267
equal(`${dt2.round({ smallestUnit, roundingMode: 'ceil' })}`, '-000099-12-15T12:00:01');
12681268
equal(`${dt2.round({ smallestUnit, roundingMode: 'floor' })}`, '-000099-12-15T12:00:00');
@@ -1404,23 +1404,27 @@ describe('DateTime', () => {
14041404
throws(() => PlainDateTime.from('2020-13-34T24:60', { overflow: 'constrain' }), RangeError);
14051405
});
14061406
});
1407+
it('Z not supported', () => {
1408+
throws(() => PlainDateTime.from('2019-10-01T09:00:00Z'), RangeError);
1409+
throws(() => PlainDateTime.from('2019-10-01T09:00:00Z[Europe/Berlin]'), RangeError);
1410+
});
14071411
it('variant time separators', () => {
1408-
equal(`${PlainDateTime.from('1976-11-18t15:23Z')}`, '1976-11-18T15:23:00');
1409-
equal(`${PlainDateTime.from('1976-11-18 15:23Z')}`, '1976-11-18T15:23:00');
1412+
equal(`${PlainDateTime.from('1976-11-18t15:23')}`, '1976-11-18T15:23:00');
1413+
equal(`${PlainDateTime.from('1976-11-18 15:23')}`, '1976-11-18T15:23:00');
14101414
});
14111415
it('any number of decimal places', () => {
1412-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1Z')}`, '1976-11-18T15:23:30.1');
1413-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12Z')}`, '1976-11-18T15:23:30.12');
1414-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123Z')}`, '1976-11-18T15:23:30.123');
1415-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1234Z')}`, '1976-11-18T15:23:30.1234');
1416-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12345Z')}`, '1976-11-18T15:23:30.12345');
1417-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123456Z')}`, '1976-11-18T15:23:30.123456');
1418-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1234567Z')}`, '1976-11-18T15:23:30.1234567');
1419-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12345678Z')}`, '1976-11-18T15:23:30.12345678');
1420-
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123456789Z')}`, '1976-11-18T15:23:30.123456789');
1416+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1')}`, '1976-11-18T15:23:30.1');
1417+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12')}`, '1976-11-18T15:23:30.12');
1418+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123')}`, '1976-11-18T15:23:30.123');
1419+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1234')}`, '1976-11-18T15:23:30.1234');
1420+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12345')}`, '1976-11-18T15:23:30.12345');
1421+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123456')}`, '1976-11-18T15:23:30.123456');
1422+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.1234567')}`, '1976-11-18T15:23:30.1234567');
1423+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12345678')}`, '1976-11-18T15:23:30.12345678');
1424+
equal(`${PlainDateTime.from('1976-11-18T15:23:30.123456789')}`, '1976-11-18T15:23:30.123456789');
14211425
});
14221426
it('variant decimal separator', () => {
1423-
equal(`${PlainDateTime.from('1976-11-18T15:23:30,12Z')}`, '1976-11-18T15:23:30.12');
1427+
equal(`${PlainDateTime.from('1976-11-18T15:23:30,12')}`, '1976-11-18T15:23:30.12');
14241428
});
14251429
it('variant minus sign', () => {
14261430
equal(`${PlainDateTime.from('1976-11-18T15:23:30.12\u221202:00')}`, '1976-11-18T15:23:30.12');

test/plainmonthday.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ describe('MonthDay', () => {
3838
it('Leap day', () => equal(`${new PlainMonthDay(2, 29)}`, '02-29'));
3939
describe('.from()', () => {
4040
it('MonthDay.from(10-01) == 10-01', () => equal(`${PlainMonthDay.from('10-01')}`, '10-01'));
41-
it('MonthDay.from(2019-10-01T09:00:00Z) == 10-01', () =>
42-
equal(`${PlainMonthDay.from('2019-10-01T09:00:00Z')}`, '10-01'));
41+
it('Z not supported', () => {
42+
throws(() => PlainMonthDay.from('2019-10-01T09:00:00Z'), RangeError);
43+
});
4344
it("MonthDay.from('11-18') == (11-18)", () => equal(`${PlainMonthDay.from('11-18')}`, '11-18'));
4445
it("MonthDay.from('1976-11-18') == (11-18)", () => equal(`${PlainMonthDay.from('1976-11-18')}`, '11-18'));
4546
it('MonthDay.from({ monthCode: "M11", day: 18 }) == 11-18', () =>

test/plaintime.mjs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,19 +1215,23 @@ describe('Time', () => {
12151215
const t = PlainTime.from('2020-02-12T11:42:00+01:00[Europe/Amsterdam]');
12161216
notEqual(PlainTime.from(t), t);
12171217
});
1218+
it('Z not supported', () => {
1219+
throws(() => PlainTime.from('2019-10-01T09:00:00Z'), RangeError);
1220+
throws(() => PlainTime.from('2019-10-01T09:00:00Z[Europe/Berlin]'), RangeError);
1221+
});
12181222
it('any number of decimal places', () => {
1219-
equal(`${PlainTime.from('1976-11-18T15:23:30.1Z')}`, '15:23:30.1');
1220-
equal(`${PlainTime.from('1976-11-18T15:23:30.12Z')}`, '15:23:30.12');
1221-
equal(`${PlainTime.from('1976-11-18T15:23:30.123Z')}`, '15:23:30.123');
1222-
equal(`${PlainTime.from('1976-11-18T15:23:30.1234Z')}`, '15:23:30.1234');
1223-
equal(`${PlainTime.from('1976-11-18T15:23:30.12345Z')}`, '15:23:30.12345');
1224-
equal(`${PlainTime.from('1976-11-18T15:23:30.123456Z')}`, '15:23:30.123456');
1225-
equal(`${PlainTime.from('1976-11-18T15:23:30.1234567Z')}`, '15:23:30.1234567');
1226-
equal(`${PlainTime.from('1976-11-18T15:23:30.12345678Z')}`, '15:23:30.12345678');
1227-
equal(`${PlainTime.from('1976-11-18T15:23:30.123456789Z')}`, '15:23:30.123456789');
1223+
equal(`${PlainTime.from('1976-11-18T15:23:30.1')}`, '15:23:30.1');
1224+
equal(`${PlainTime.from('1976-11-18T15:23:30.12')}`, '15:23:30.12');
1225+
equal(`${PlainTime.from('1976-11-18T15:23:30.123')}`, '15:23:30.123');
1226+
equal(`${PlainTime.from('1976-11-18T15:23:30.1234')}`, '15:23:30.1234');
1227+
equal(`${PlainTime.from('1976-11-18T15:23:30.12345')}`, '15:23:30.12345');
1228+
equal(`${PlainTime.from('1976-11-18T15:23:30.123456')}`, '15:23:30.123456');
1229+
equal(`${PlainTime.from('1976-11-18T15:23:30.1234567')}`, '15:23:30.1234567');
1230+
equal(`${PlainTime.from('1976-11-18T15:23:30.12345678')}`, '15:23:30.12345678');
1231+
equal(`${PlainTime.from('1976-11-18T15:23:30.123456789')}`, '15:23:30.123456789');
12281232
});
12291233
it('variant decimal separator', () => {
1230-
equal(`${PlainTime.from('1976-11-18T15:23:30,12Z')}`, '15:23:30.12');
1234+
equal(`${PlainTime.from('1976-11-18T15:23:30,12')}`, '15:23:30.12');
12311235
});
12321236
it('variant minus sign', () => {
12331237
equal(`${PlainTime.from('1976-11-18T15:23:30.12\u221202:00')}`, '15:23:30.12');

test/plainyearmonth.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ describe('YearMonth', () => {
6767
it('ym.monthsInYear is 12', () => equal(ym.monthsInYear, 12));
6868
describe('.from()', () => {
6969
it('YearMonth.from(2019-10) == 2019-10', () => equal(`${PlainYearMonth.from('2019-10')}`, '2019-10'));
70-
it('YearMonth.from(2019-10-01T09:00:00Z) == 2019-10', () =>
71-
equal(`${PlainYearMonth.from('2019-10-01T09:00:00Z')}`, '2019-10'));
70+
it('YearMonth.from(2019-10-01T09:00:00+00:00) == 2019-10', () =>
71+
equal(`${PlainYearMonth.from('2019-10-01T09:00:00+00:00')}`, '2019-10'));
72+
it('Z not supported', () => {
73+
throws(() => PlainYearMonth.from('2019-10-01T09:00:00Z'), RangeError);
74+
throws(() => PlainYearMonth.from('2019-10-01T09:00:00Z[Europe/Berlin]'), RangeError);
75+
});
7276
it("YearMonth.from('1976-11') == (1976-11)", () => equal(`${PlainYearMonth.from('1976-11')}`, '1976-11'));
7377
it("YearMonth.from('1976-11-18') == (1976-11)", () => equal(`${PlainYearMonth.from('1976-11-18')}`, '1976-11'));
7478
it('can be constructed with monthCode and without month', () =>

test/regex.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('fromString regex', () => {
160160
test('1976-11-18T15', [1976, 11, 18, 15]);
161161
test('1976-11-18', [1976, 11, 18]);
162162
// Representations with calendar
163-
['', 'Z', '+01:00[Europe/Vienna]', '+01:00[Custom/Vienna]', '[Europe/Vienna]'].forEach((zoneString) =>
163+
['', '+01:00[Europe/Vienna]', '+01:00[Custom/Vienna]', '[Europe/Vienna]'].forEach((zoneString) =>
164164
test(`1976-11-18T15:23:30.123456789${zoneString}[u-ca=iso8601]`, [1976, 11, 18, 15, 23, 30, 123, 456, 789])
165165
);
166166
});
@@ -240,7 +240,7 @@ describe('fromString regex', () => {
240240
test('1512-11-18', [1512, 11, 18]);
241241
test('15121118', [1512, 11, 18]);
242242
// Representations with calendar
243-
['', 'Z', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
243+
['', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
244244
test(`1976-11-18T15:23:30.123456789${zoneString}[u-ca=iso8601]`, [1976, 11, 18])
245245
);
246246
test('1976-11-18[u-ca=iso8601]', [1976, 11, 18]);
@@ -304,7 +304,7 @@ describe('fromString regex', () => {
304304
test(`15${zoneStr}`, [15])
305305
);
306306
// Representations with calendar
307-
['', 'Z', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
307+
['', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
308308
test(`1976-11-18T15:23:30.123456789${zoneString}[u-ca=iso8601]`, [15, 23, 30, 123, 456, 789])
309309
);
310310
test('15:23:30.123456789[u-ca=iso8601]', [15, 23, 30, 123, 456, 789]);
@@ -357,7 +357,7 @@ describe('fromString regex', () => {
357357
'1976-11-18T15'
358358
].forEach((str) => test(str, [1976, 11]));
359359
// Unicode minus sign
360-
test('\u2212009999-11-18T15:23:30.1234Z', [-9999, 11]);
360+
test('\u2212009999-11-18T15:23:30.1234', [-9999, 11]);
361361
// Date-only forms
362362
test('1976-11-18', [1976, 11]);
363363
test('19761118', [1976, 11]);
@@ -377,7 +377,7 @@ describe('fromString regex', () => {
377377
test('1512-11', [1512, 11]);
378378
test('151211', [1512, 11]);
379379
// Representations with calendar
380-
['', 'Z', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
380+
['', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
381381
test(`1976-11-18T15:23:30.123456789${zoneString}[u-ca=iso8601]`, [1976, 11])
382382
);
383383
test('1976-11-01[u-ca=iso8601]', [1976, 11]);
@@ -453,7 +453,7 @@ describe('fromString regex', () => {
453453
test('--11-18', [11, 18]);
454454
test('--1118', [11, 18]);
455455
// Representations with calendar
456-
['', 'Z', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
456+
['', '+01:00[Europe/Vienna]', '[Europe/Vienna]', '+01:00[Custom/Vienna]'].forEach((zoneString) =>
457457
test(`1976-11-18T15:23:30.123456789${zoneString}[u-ca=iso8601]`, [11, 18])
458458
);
459459
test('1972-11-18[u-ca=iso8601]', [11, 18]);

0 commit comments

Comments
 (0)