basic.js (1773B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2022 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-temporal.instant.from 7 description: Basic functionality of Temporal.Instant.from 8 features: [Temporal] 9 ---*/ 10 11 const baseValue = 217_178_580_000_000_000n; 12 13 let instant = Temporal.Instant.from("1976-11-18T15:23Z"); 14 assert.sameValue( 15 instant.epochNanoseconds, 16 baseValue, 17 "ISO string with UTC designator and minutes precision" 18 ); 19 20 instant = Temporal.Instant.from("1976-11-18T15:23:30Z"); 21 assert.sameValue( 22 instant.epochNanoseconds, 23 baseValue + 30_000_000_000n, 24 "ISO string with UTC designator and seconds precision" 25 ); 26 27 instant = Temporal.Instant.from("1976-11-18T15:23:30.123Z"); 28 assert.sameValue( 29 instant.epochNanoseconds, 30 baseValue + 30_123_000_000n, 31 "ISO string with UTC designator and milliseconds precision" 32 ); 33 34 instant = Temporal.Instant.from("1976-11-18T15:23:30.123456Z"); 35 assert.sameValue( 36 instant.epochNanoseconds, 37 baseValue + 30_123_456_000n, 38 "ISO string with UTC designator and microseconds precision" 39 ); 40 41 instant = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); 42 assert.sameValue( 43 instant.epochNanoseconds, 44 baseValue + 30_123_456_789n, 45 "ISO string with UTC designator and nanoseconds precision" 46 ); 47 48 instant = Temporal.Instant.from("1976-11-18T15:23-01:00"); 49 assert.sameValue( 50 instant.epochNanoseconds, 51 baseValue + 3600_000_000_000n, 52 "ISO string with negative UTC offset" 53 ); 54 55 instant = Temporal.Instant.from("1976-11-18T15:23+01:00"); 56 assert.sameValue( 57 instant.epochNanoseconds, 58 baseValue - 3600_000_000_000n, 59 "ISO string with positive UTC offset" 60 ); 61 62 reportCompare(0, 0);