diff --git a/polyfill/lib/civildate.mjs b/polyfill/lib/civildate.mjs index d460f23bee..dcd6f3b6d5 100644 --- a/polyfill/lib/civildate.mjs +++ b/polyfill/lib/civildate.mjs @@ -28,10 +28,13 @@ export class CivilDate { withTime(time) { return new CivilDateTime.from(this, time); } - toString() { + asString() { const { year, month, day } = this; return `${spad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}`; } + toString() { + return `[object CivilDate ${this.asString()}]`; + } static fromString(string) { const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(string); diff --git a/polyfill/lib/civildatetime.mjs b/polyfill/lib/civildatetime.mjs index b5f7ca660b..acc6611964 100644 --- a/polyfill/lib/civildatetime.mjs +++ b/polyfill/lib/civildatetime.mjs @@ -48,10 +48,13 @@ export class CivilDateTime { instant[VALUE] = { milliseconds, nanoseconds }; return new ZonedInstant(instant, zone); } - toString() { + asString() { const { year, month, day, hour, minute, second, millisecond, nanosecond } = this; return `${spad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(millisecond,3)}${pad(nanosecond, 6)}`; } + toString() { + return `[object CivilDateTime ${this.asString()}]`; + } static fromString(string) { const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(\d{6})$/.exec(string); diff --git a/polyfill/lib/civiltime.mjs b/polyfill/lib/civiltime.mjs index 829cc7bca9..ac07a094be 100644 --- a/polyfill/lib/civiltime.mjs +++ b/polyfill/lib/civiltime.mjs @@ -37,10 +37,13 @@ export class CivilTime { withDate(date) { return new CivilDateTime.from(date, this); } - toString() { + asString() { const { hour, minute, second, millisecond, nanosecond } = this; return `${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(millisecond, 3)}${pad(nanosecond, 6)}`; } + toString() { + return `[object CivilTime ${this.asString()}]`; + } static fromString(string) { const match = /^(\d{2}):(\d{2}):(\d{2})\.(\d{3})(\d{6})$/.exec(string); diff --git a/polyfill/lib/instant.mjs b/polyfill/lib/instant.mjs index f37aa8d982..2f88065616 100644 --- a/polyfill/lib/instant.mjs +++ b/polyfill/lib/instant.mjs @@ -37,11 +37,14 @@ export class Instant { format(locale, options) { return this.withZone().format(locale, options); } - toString() { + asString() { const { year, month, day, hour, minute, second, millisecond } = fromEpoch(this.milliseconds, 'UTC'); const nanosecond = this.nanoseconds; return `${spad(year,4)}-${pad(month,2)}-${pad(day,2)}T${pad(hour,2)}:${pad(minute,2)}:${pad(second,2)}.${pad(millisecond,3)}${pad(nanosecond,6)}Z`; } + toString() { + return `[object Instant ${this.asString()}]`; + } static fromString(string) { const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(\d{6})Z$/.exec(string); diff --git a/polyfill/lib/zonedinstant.mjs b/polyfill/lib/zonedinstant.mjs index 20123fad96..8e5d1752a8 100644 --- a/polyfill/lib/zonedinstant.mjs +++ b/polyfill/lib/zonedinstant.mjs @@ -47,13 +47,16 @@ export class ZonedInstant{ ); return fmt.format(new Date(this.toInstant().milliseconds)); } - toString() { + asString() { const ts = this[INSTANT].milliseconds; const { year, month, day, hour, minute, second, millisecond } = fromEpoch(ts, this[ZONE]); const nanosecond = this[INSTANT].nanoseconds; const offset = ([ 'UTC', '+00:00', '-00:00' ].indexOf(this[ZONE]) > -1) ? 'Z' : zoneOffset(ts, this[ZONE]); return `${spad(year,4)}-${pad(month,2)}-${pad(day,2)}T${pad(hour,2)}:${pad(minute,2)}:${pad(second,2)}.${pad(millisecond,3)}${pad(nanosecond,6)}${offset}`; } + toString() { + return `[object ZonedInstant ${this.asString()}]`; + } static fromString(string) { const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(\d{6})(Z|[+-]\d{2}:\d{2})$/.exec(string); diff --git a/polyfill/test/compat/civildate.js b/polyfill/test/compat/civildate.js index 2946343efa..70d45a9255 100644 --- a/polyfill/test/compat/civildate.js +++ b/polyfill/test/compat/civildate.js @@ -15,7 +15,8 @@ test('CivilDate', ({ test, end })=>{ equal(instance.second, undefined); equal(instance.millisecond, undefined); equal(instance.nanosecond, undefined); - equal(instance.toString(), '1976-11-18'); + equal(instance.asString(), '1976-11-18'); + equal(instance.toString(), '[object CivilDate 1976-11-18]'); end(); }); diff --git a/polyfill/test/compat/civildatetime.js b/polyfill/test/compat/civildatetime.js index 573783d1b5..3ce4e48a08 100644 --- a/polyfill/test/compat/civildatetime.js +++ b/polyfill/test/compat/civildatetime.js @@ -4,38 +4,39 @@ const { CivilDateTime } = require('../../'); test('CivilDateTime', ({ test, end })=>{ test('simple', ({ equal, end })=>{ const instance = new CivilDateTime(1976, 11, 18, 15, 23, 30); + equal('[object CivilDateTime 1976-11-18T15:23:30.000000000]', instance.toString()); - equal('1976-11-18T15:23:30.000000000', instance.toString()); - equal('1976-11-18T15:23:30.000000000+01:00', instance.withZone('Europe/Berlin').toString()); + equal('1976-11-18T15:23:30.000000000', instance.asString()); + equal('1976-11-18T15:23:30.000000000+01:00', instance.withZone('Europe/Berlin').asString()); const anniversary = instance.plus({ years: 3 }); - equal('1979-11-18T15:23:30.000000000', anniversary.toString()); - equal('1979-11-18T15:23:30.000000000+01:00', anniversary.withZone('Europe/Berlin').toString()); + equal('1979-11-18T15:23:30.000000000', anniversary.asString()); + equal('1979-11-18T15:23:30.000000000+01:00', anniversary.withZone('Europe/Berlin').asString()); const runup = anniversary.plus({ months: -1 }); - equal('1979-10-18T15:23:30.000000000', runup.toString()); - equal('1979-10-18T15:23:30.000000000+01:00', runup.withZone('Europe/Berlin').toString()); + equal('1979-10-18T15:23:30.000000000', runup.asString()); + equal('1979-10-18T15:23:30.000000000+01:00', runup.withZone('Europe/Berlin').asString()); const thirty = runup.plus({ days: 30 }); - equal('1979-11-17T15:23:30.000000000', thirty.toString()); - equal('1979-11-17T15:23:30.000000000+01:00', thirty.withZone('Europe/Berlin').toString()); + equal('1979-11-17T15:23:30.000000000', thirty.asString()); + equal('1979-11-17T15:23:30.000000000+01:00', thirty.withZone('Europe/Berlin').asString()); const preptime = anniversary.plus({ hours: -5, minutes: 37, seconds: 30, milliseconds: 4, nanoseconds: -3 }); - equal('1979-11-18T11:01:00.003999997', preptime.toString()); - equal('1979-11-18T11:01:00.003999997+01:00', preptime.withZone('Europe/Berlin').toString()); + equal('1979-11-18T11:01:00.003999997', preptime.asString()); + equal('1979-11-18T11:01:00.003999997+01:00', preptime.withZone('Europe/Berlin').asString()); const daybreak = anniversary.with({ hour: 0, minute: 0, second: 0 }); - equal('1979-11-18T00:00:00.000000000', daybreak.toString()); - equal('1979-11-18T00:00:00.000000000+01:00', daybreak.withZone('Europe/Berlin').toString()); + equal('1979-11-18T00:00:00.000000000', daybreak.asString()); + equal('1979-11-18T00:00:00.000000000+01:00', daybreak.withZone('Europe/Berlin').asString()); const nightfall = anniversary.with({ hour: 23, minute: 59, second: 59, millisecond: 1000, nanosecond: -1 }); - equal('1979-11-18T23:59:59.999999999', nightfall.toString()); - equal('1979-11-18T23:59:59.999999999+01:00', nightfall.withZone('Europe/Berlin').toString()); + equal('1979-11-18T23:59:59.999999999', nightfall.asString()); + equal('1979-11-18T23:59:59.999999999+01:00', nightfall.withZone('Europe/Berlin').asString()); const year = (new Date()).getFullYear() const birthday = instance.with({ year }); - equal(`${year}-11-18T15:23:30.000000000`, birthday.toString()); - equal(`${year}-11-18T15:23:30.000000000+01:00`, birthday.withZone('Europe/Berlin').toString()); + equal(`${year}-11-18T15:23:30.000000000`, birthday.asString()); + equal(`${year}-11-18T15:23:30.000000000+01:00`, birthday.withZone('Europe/Berlin').asString()); end(); }); @@ -53,7 +54,7 @@ test('CivilDateTime', ({ test, end })=>{ equal(instance.second, 30); equal(instance.millisecond, 450); equal(instance.nanosecond, 12345); - equal(instance.toString(), '1976-11-18T15:23:30.450012345'); + equal(instance.asString(), '1976-11-18T15:23:30.450012345'); end(); }); diff --git a/polyfill/test/compat/civiltime.js b/polyfill/test/compat/civiltime.js index f63c01866b..90ddd337db 100644 --- a/polyfill/test/compat/civiltime.js +++ b/polyfill/test/compat/civiltime.js @@ -15,7 +15,8 @@ test('CivilTime', ({ test, end })=>{ equal(instance.second, 30); equal(instance.millisecond, 450); equal(instance.nanosecond, 12345); - equal(instance.toString(), '15:23:30.450012345'); + equal(instance.asString(), '15:23:30.450012345'); + equal(instance.toString(), '[object CivilTime 15:23:30.450012345]'); end(); }); diff --git a/polyfill/test/compat/instant.js b/polyfill/test/compat/instant.js index 43da020fde..2dff71726d 100644 --- a/polyfill/test/compat/instant.js +++ b/polyfill/test/compat/instant.js @@ -5,11 +5,12 @@ test('Instant', ({ test, end})=>{ test('simple', ({ equal, end })=>{ const instant = Instant.fromMilliseconds(0); - equal('1970-01-01T00:00:00.000000000Z', instant.toString()); + equal('[object Instant 1970-01-01T00:00:00.000000000Z]', instant.toString()); + equal('1970-01-01T00:00:00.000000000Z', instant.asString()); const now = new Date(); const nowi = Instant.fromMilliseconds(now); - equal(now.toISOString().replace('Z','000000Z'), nowi.toString()); + equal(now.toISOString().replace('Z','000000Z'), nowi.asString()); end(); }); @@ -20,7 +21,7 @@ test('Instant', ({ test, end})=>{ equal(instance instanceof Instant, true); equal(instance.milliseconds, 217178610450); equal(instance.nanoseconds, 0); - equal(instance.toString(), '1976-11-18T15:23:30.450000000Z'); + equal(instance.asString(), '1976-11-18T15:23:30.450000000Z'); end(); }); diff --git a/polyfill/test/compat/zonedinstant.js b/polyfill/test/compat/zonedinstant.js index f85a3c24c2..8a45afa738 100644 --- a/polyfill/test/compat/zonedinstant.js +++ b/polyfill/test/compat/zonedinstant.js @@ -15,7 +15,8 @@ test('ZonedInstant', ({ test, end})=>{ equal(instance instanceof ZonedInstant, true); equal(instance.milliseconds, 217175010450); equal(instance.nanoseconds, 0); - equal(instance.toString(), '1976-11-18T15:23:30.450000000+01:00'); + equal(instance.asString(), '1976-11-18T15:23:30.450000000+01:00'); + equal(instance.toString(), '[object ZonedInstant 1976-11-18T15:23:30.450000000+01:00]'); end(); }); diff --git a/polyfill/test/temporal/CivilDate/constructor.js b/polyfill/test/temporal/CivilDate/constructor.js index 644c53c5c6..bbf33532ef 100644 --- a/polyfill/test/temporal/CivilDate/constructor.js +++ b/polyfill/test/temporal/CivilDate/constructor.js @@ -20,4 +20,5 @@ assert.sameValue(instance.minute, undefined); assert.sameValue(instance.second, undefined); assert.sameValue(instance.millisecond, undefined); assert.sameValue(instance.nanosecond, undefined); -assert.sameValue(instance.toString(), '1976-11-18'); +assert.sameValue(instance.asString(), '1976-11-18'); +assert.sameValue(instance.toString(), '[object CivilDate 1976-11-18]'); diff --git a/polyfill/test/temporal/CivilDateTime/basic.js b/polyfill/test/temporal/CivilDateTime/basic.js index 255433f62f..34f6c76c46 100644 --- a/polyfill/test/temporal/CivilDateTime/basic.js +++ b/polyfill/test/temporal/CivilDateTime/basic.js @@ -10,34 +10,36 @@ esid: pending const instance = new temporal.CivilDateTime(1976, 11, 18, 15, 23, 30); -assert.sameValue('1976-11-18T15:23:30.000000000', instance.toString()); -assert.sameValue('1976-11-18T15:23:30.000000000+01:00', instance.withZone('Europe/Berlin').toString()); +assert.sameValue('[object CivilDateTime 1976-11-18T15:23:30.000000000]', instance.toString()); + +assert.sameValue('1976-11-18T15:23:30.000000000', instance.asString()); +assert.sameValue('1976-11-18T15:23:30.000000000+01:00', instance.withZone('Europe/Berlin').asString()); const anniversary = instance.plus({ years: 3 }); -assert.sameValue('1979-11-18T15:23:30.000000000', anniversary.toString()); -assert.sameValue('1979-11-18T15:23:30.000000000+01:00', anniversary.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-11-18T15:23:30.000000000', anniversary.asString()); +assert.sameValue('1979-11-18T15:23:30.000000000+01:00', anniversary.withZone('Europe/Berlin').asString()); const runup = anniversary.plus({ months: -1 }); -assert.sameValue('1979-10-18T15:23:30.000000000', runup.toString()); -assert.sameValue('1979-10-18T15:23:30.000000000+01:00', runup.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-10-18T15:23:30.000000000', runup.asString()); +assert.sameValue('1979-10-18T15:23:30.000000000+01:00', runup.withZone('Europe/Berlin').asString()); const thirty = runup.plus({ days: 30 }); -assert.sameValue('1979-11-17T15:23:30.000000000', thirty.toString()); -assert.sameValue('1979-11-17T15:23:30.000000000+01:00', thirty.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-11-17T15:23:30.000000000', thirty.asString()); +assert.sameValue('1979-11-17T15:23:30.000000000+01:00', thirty.withZone('Europe/Berlin').asString()); const preptime = anniversary.plus({ hours: -5, minutes: 37, seconds: 30, milliseconds: 4, nanoseconds: -3 }); -assert.sameValue('1979-11-18T11:01:00.003999997', preptime.toString()); -assert.sameValue('1979-11-18T11:01:00.003999997+01:00', preptime.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-11-18T11:01:00.003999997', preptime.asString()); +assert.sameValue('1979-11-18T11:01:00.003999997+01:00', preptime.withZone('Europe/Berlin').asString()); const daybreak = anniversary.with({ hour: 0, minute: 0, second: 0 }); -assert.sameValue('1979-11-18T00:00:00.000000000', daybreak.toString()); -assert.sameValue('1979-11-18T00:00:00.000000000+01:00', daybreak.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-11-18T00:00:00.000000000', daybreak.asString()); +assert.sameValue('1979-11-18T00:00:00.000000000+01:00', daybreak.withZone('Europe/Berlin').asString()); const nightfall = anniversary.with({ hour: 23, minute: 59, second: 59, millisecond: 1000, nanosecond: -1 }); -assert.sameValue('1979-11-18T23:59:59.999999999', nightfall.toString()); -assert.sameValue('1979-11-18T23:59:59.999999999+01:00', nightfall.withZone('Europe/Berlin').toString()); +assert.sameValue('1979-11-18T23:59:59.999999999', nightfall.asString()); +assert.sameValue('1979-11-18T23:59:59.999999999+01:00', nightfall.withZone('Europe/Berlin').asString()); const year = (new Date()).getFullYear() const birthday = instance.with({ year }); -assert.sameValue(`${year}-11-18T15:23:30.000000000`, birthday.toString()); -assert.sameValue(`${year}-11-18T15:23:30.000000000+01:00`, birthday.withZone('Europe/Berlin').toString()); +assert.sameValue(`${year}-11-18T15:23:30.000000000`, birthday.asString()); +assert.sameValue(`${year}-11-18T15:23:30.000000000+01:00`, birthday.withZone('Europe/Berlin').asString()); diff --git a/polyfill/test/temporal/CivilDateTime/constructor.js b/polyfill/test/temporal/CivilDateTime/constructor.js index 7ee4eac3d2..8a01dde20b 100644 --- a/polyfill/test/temporal/CivilDateTime/constructor.js +++ b/polyfill/test/temporal/CivilDateTime/constructor.js @@ -20,4 +20,5 @@ assert.sameValue(instance.minute, 23); assert.sameValue(instance.second, 30); assert.sameValue(instance.millisecond, 450); assert.sameValue(instance.nanosecond, 12345); -assert.sameValue(instance.toString(), '1976-11-18T15:23:30.450012345'); +assert.sameValue(instance.asString(), '1976-11-18T15:23:30.450012345'); +assert.sameValue(instance.toString(), '[object CivilDateTime 1976-11-18T15:23:30.450012345]'); diff --git a/polyfill/test/temporal/CivilTime/constructor.js b/polyfill/test/temporal/CivilTime/constructor.js index f81e8c72e7..d6409bb194 100644 --- a/polyfill/test/temporal/CivilTime/constructor.js +++ b/polyfill/test/temporal/CivilTime/constructor.js @@ -20,4 +20,5 @@ assert.sameValue(instance.minute, 23); assert.sameValue(instance.second, 30); assert.sameValue(instance.millisecond, 450); assert.sameValue(instance.nanosecond, 12345); -assert.sameValue(instance.toString(), '15:23:30.450012345'); +assert.sameValue(instance.asString(), '15:23:30.450012345'); +assert.sameValue(instance.toString(), '[object CivilTime 15:23:30.450012345]'); diff --git a/polyfill/test/temporal/Instant/basic.js b/polyfill/test/temporal/Instant/basic.js index 724d9745ce..2d3505e9e5 100644 --- a/polyfill/test/temporal/Instant/basic.js +++ b/polyfill/test/temporal/Instant/basic.js @@ -9,9 +9,10 @@ esid: pending ---*/ const instant = new temporal.Instant(0n); +assert.sameValue('[object Instant 1970-01-01T00:00:00.000000000Z]', instant.toString()); -assert.sameValue('1970-01-01T00:00:00.000000000Z', instant.toString()); +assert.sameValue('1970-01-01T00:00:00.000000000Z', instant.asString()); const now = new Date(); const nowi = new temporal.Instant(BigInt(now.valueOf()) * BigInt(1e6)); -assert.sameValue(now.toISOString().replace('Z','000000Z'), nowi.toString()); +assert.sameValue(now.toISOString().replace('Z','000000Z'), nowi.asString()); diff --git a/polyfill/test/temporal/Instant/constructor.js b/polyfill/test/temporal/Instant/constructor.js index 1db0049ed3..30a3b52c5f 100644 --- a/polyfill/test/temporal/Instant/constructor.js +++ b/polyfill/test/temporal/Instant/constructor.js @@ -15,4 +15,5 @@ assert.sameValue(instance instanceof temporal.Instant, true); assert.sameValue(instance.milliseconds, 217178610450); assert.sameValue(instance.nanoseconds, 100); assert.sameValue(instance.value, 217178610450000100n); -assert.sameValue(instance.toString(), '1976-11-18T15:23:30.450000100Z'); +assert.sameValue(instance.asString(), '1976-11-18T15:23:30.450000100Z'); +assert.sameValue(instance.toString(), '[object Instant 1976-11-18T15:23:30.450000100Z]'); diff --git a/polyfill/test/temporal/ZonedInstant/constructor.js b/polyfill/test/temporal/ZonedInstant/constructor.js index b0b369f85a..fe11cb0fb5 100644 --- a/polyfill/test/temporal/ZonedInstant/constructor.js +++ b/polyfill/test/temporal/ZonedInstant/constructor.js @@ -16,7 +16,8 @@ assert.sameValue(one instanceof temporal.ZonedInstant, true); assert.sameValue(one.milliseconds, 217175010450); assert.sameValue(one.nanoseconds, 100); assert.sameValue(one.value, 217175010450000100n); -assert.sameValue(one.toString(), '1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(one.asString(), '1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(one.toString(), '[object ZonedInstant 1976-11-18T15:23:30.450000100+01:00]'); const two = new temporal.ZonedInstant(instant, 'America/New_York'); assert.sameValue(typeof two, 'object'); @@ -24,4 +25,5 @@ assert.sameValue(two instanceof temporal.ZonedInstant, true); assert.sameValue(two.milliseconds, 217175010450); assert.sameValue(two.nanoseconds, 100); assert.sameValue(two.value, 217175010450000100n); -assert.sameValue(two.toString(), '1976-11-18T09:23:30.450000100-05:00'); +assert.sameValue(two.asString(), '1976-11-18T09:23:30.450000100-05:00'); +assert.sameValue(two.toString(), '[object ZonedInstant 1976-11-18T09:23:30.450000100-05:00]');