@@ -18,87 +18,6 @@ import * as Temporal from '@js-temporal/polyfill';
18
18
const { PlainDateTime } = Temporal ;
19
19
20
20
describe ( 'DateTime' , ( ) => {
21
- describe ( 'Min/max range' , ( ) => {
22
- it ( 'constructing from numbers' , ( ) => {
23
- throws ( ( ) => new PlainDateTime ( - 271821 , 4 , 19 , 0 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
24
- throws ( ( ) => new PlainDateTime ( 275760 , 9 , 14 , 0 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
25
- equal ( `${ new PlainDateTime ( - 271821 , 4 , 19 , 0 , 0 , 0 , 0 , 0 , 1 ) } ` , '-271821-04-19T00:00:00.000000001' ) ;
26
- equal ( `${ new PlainDateTime ( 275760 , 9 , 13 , 23 , 59 , 59 , 999 , 999 , 999 ) } ` , '+275760-09-13T23:59:59.999999999' ) ;
27
- } ) ;
28
- it ( 'constructing from property bag' , ( ) => {
29
- const tooEarly = { year : - 271821 , month : 4 , day : 19 } ;
30
- const tooLate = { year : 275760 , month : 9 , day : 14 } ;
31
- [ 'reject' , 'constrain' ] . forEach ( ( overflow ) => {
32
- [ tooEarly , tooLate ] . forEach ( ( props ) => {
33
- throws ( ( ) => PlainDateTime . from ( props , { overflow } ) , RangeError ) ;
34
- } ) ;
35
- } ) ;
36
- equal (
37
- `${ PlainDateTime . from ( { year : - 271821 , month : 4 , day : 19 , nanosecond : 1 } ) } ` ,
38
- '-271821-04-19T00:00:00.000000001'
39
- ) ;
40
- equal (
41
- `${ PlainDateTime . from ( {
42
- year : 275760 ,
43
- month : 9 ,
44
- day : 13 ,
45
- hour : 23 ,
46
- minute : 59 ,
47
- second : 59 ,
48
- millisecond : 999 ,
49
- microsecond : 999 ,
50
- nanosecond : 999
51
- } ) } `,
52
- '+275760-09-13T23:59:59.999999999'
53
- ) ;
54
- } ) ;
55
- it ( 'constructing from ISO string' , ( ) => {
56
- [ 'reject' , 'constrain' ] . forEach ( ( overflow ) => {
57
- [ '-271821-04-19T00:00' , '+275760-09-14T00:00' ] . forEach ( ( str ) => {
58
- throws ( ( ) => PlainDateTime . from ( str , { overflow } ) , RangeError ) ;
59
- } ) ;
60
- } ) ;
61
- equal ( `${ PlainDateTime . from ( '-271821-04-19T00:00:00.000000001' ) } ` , '-271821-04-19T00:00:00.000000001' ) ;
62
- equal ( `${ PlainDateTime . from ( '+275760-09-13T23:59:59.999999999' ) } ` , '+275760-09-13T23:59:59.999999999' ) ;
63
- } ) ;
64
- it ( 'converting from Instant' , ( ) => {
65
- const min = Temporal . Instant . from ( '-271821-04-20T00:00Z' ) ;
66
- const offsetMin = Temporal . TimeZone . from ( '-23:59' ) ;
67
- equal ( `${ offsetMin . getPlainDateTimeFor ( min , 'iso8601' ) } ` , '-271821-04-19T00:01:00' ) ;
68
- const max = Temporal . Instant . from ( '+275760-09-13T00:00Z' ) ;
69
- const offsetMax = Temporal . TimeZone . from ( '+23:59' ) ;
70
- equal ( `${ offsetMax . getPlainDateTimeFor ( max , 'iso8601' ) } ` , '+275760-09-13T23:59:00' ) ;
71
- } ) ;
72
- it ( 'converting from Date and Time' , ( ) => {
73
- const midnight = Temporal . PlainTime . from ( '00:00' ) ;
74
- const firstNs = Temporal . PlainTime . from ( '00:00:00.000000001' ) ;
75
- const lastNs = Temporal . PlainTime . from ( '23:59:59.999999999' ) ;
76
- const min = Temporal . PlainDate . from ( '-271821-04-19' ) ;
77
- const max = Temporal . PlainDate . from ( '+275760-09-13' ) ;
78
- throws ( ( ) => min . toPlainDateTime ( midnight ) , RangeError ) ;
79
- throws ( ( ) => midnight . toPlainDateTime ( min ) , RangeError ) ;
80
- equal ( `${ min . toPlainDateTime ( firstNs ) } ` , '-271821-04-19T00:00:00.000000001' ) ;
81
- equal ( `${ firstNs . toPlainDateTime ( min ) } ` , '-271821-04-19T00:00:00.000000001' ) ;
82
- equal ( `${ max . toPlainDateTime ( lastNs ) } ` , '+275760-09-13T23:59:59.999999999' ) ;
83
- equal ( `${ lastNs . toPlainDateTime ( max ) } ` , '+275760-09-13T23:59:59.999999999' ) ;
84
- } ) ;
85
- it ( 'adding and subtracting beyond limit' , ( ) => {
86
- const min = PlainDateTime . from ( '-271821-04-19T00:00:00.000000001' ) ;
87
- const max = PlainDateTime . from ( '+275760-09-13T23:59:59.999999999' ) ;
88
- [ 'reject' , 'constrain' ] . forEach ( ( overflow ) => {
89
- throws ( ( ) => min . subtract ( { nanoseconds : 1 } , { overflow } ) , RangeError ) ;
90
- throws ( ( ) => max . add ( { nanoseconds : 1 } , { overflow } ) , RangeError ) ;
91
- } ) ;
92
- } ) ;
93
- it ( 'rounding beyond limit' , ( ) => {
94
- const min = PlainDateTime . from ( '-271821-04-19T00:00:00.000000001' ) ;
95
- const max = PlainDateTime . from ( '+275760-09-13T23:59:59.999999999' ) ;
96
- [ 'day' , 'hour' , 'minute' , 'second' , 'millisecond' , 'microsecond' ] . forEach ( ( smallestUnit ) => {
97
- throws ( ( ) => min . round ( { smallestUnit, roundingMode : 'floor' } ) , RangeError ) ;
98
- throws ( ( ) => max . round ( { smallestUnit, roundingMode : 'ceil' } ) , RangeError ) ;
99
- } ) ;
100
- } ) ;
101
- } ) ;
102
21
describe ( 'dateTime.withCalendar()' , ( ) => {
103
22
const dt1 = PlainDateTime . from ( '1976-11-18T15:23:30.123456789' ) ;
104
23
it ( 'works' , ( ) => {
0 commit comments