@@ -687,6 +687,15 @@ describe('Duration', () => {
687687 throws ( ( ) => oneDay . add ( hours24 , { relativeTo : { year : 2019 , month : 11 } } ) , TypeError ) ;
688688 throws ( ( ) => oneDay . add ( hours24 , { relativeTo : { year : 2019 , day : 3 } } ) , TypeError ) ;
689689 } ) ;
690+ it ( 'throws with invalid offset in relativeTo' , ( ) => {
691+ throws (
692+ ( ) =>
693+ Temporal . Duration . from ( 'P2D' ) . add ( 'P1M' , {
694+ relativeTo : { year : 2021 , month : 11 , day : 26 , offset : '+088:00' , timeZone : 'Europe/London' }
695+ } ) ,
696+ RangeError
697+ ) ;
698+ } ) ;
690699 } ) ;
691700 describe ( 'Duration.subtract()' , ( ) => {
692701 const duration = Duration . from ( { days : 3 , hours : 1 , minutes : 10 } ) ;
@@ -930,6 +939,15 @@ describe('Duration', () => {
930939 equal ( zero2 . microseconds , 0 ) ;
931940 equal ( zero2 . nanoseconds , 0 ) ;
932941 } ) ;
942+ it ( 'throws with invalid offset in relativeTo' , ( ) => {
943+ throws (
944+ ( ) =>
945+ Temporal . Duration . from ( 'P2D' ) . subtract ( 'P1M' , {
946+ relativeTo : { year : 2021 , month : 11 , day : 26 , offset : '+088:00' , timeZone : 'Europe/London' }
947+ } ) ,
948+ RangeError
949+ ) ;
950+ } ) ;
933951 } ) ;
934952 describe ( 'Duration.abs()' , ( ) => {
935953 it ( 'makes a copy of a positive duration' , ( ) => {
@@ -1514,6 +1532,16 @@ describe('Duration', () => {
15141532 equal ( `${ yearAndHalf . round ( { relativeTo : '2020-01-01' , smallestUnit : 'years' } ) } ` , 'P1Y' ) ;
15151533 equal ( `${ yearAndHalf . round ( { relativeTo : '2020-07-01' , smallestUnit : 'years' } ) } ` , 'P2Y' ) ;
15161534 } ) ;
1535+ it ( 'throws with invalid offset in relativeTo' , ( ) => {
1536+ throws (
1537+ ( ) =>
1538+ Temporal . Duration . from ( 'P1M280D' ) . round ( {
1539+ smallestUnit : 'month' ,
1540+ relativeTo : { year : 2021 , month : 11 , day : 26 , offset : '+088:00' , timeZone : 'Europe/London' }
1541+ } ) ,
1542+ RangeError
1543+ ) ;
1544+ } ) ;
15171545 } ) ;
15181546 describe ( 'Duration.total()' , ( ) => {
15191547 const d = new Duration ( 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
@@ -1853,6 +1881,16 @@ describe('Duration', () => {
18531881 equal ( d . total ( { unit : 'microsecond' , relativeTo } ) , d . total ( { unit : 'microseconds' , relativeTo } ) ) ;
18541882 equal ( d . total ( { unit : 'nanosecond' , relativeTo } ) , d . total ( { unit : 'nanoseconds' , relativeTo } ) ) ;
18551883 } ) ;
1884+ it ( 'throws with invalid offset in relativeTo' , ( ) => {
1885+ throws (
1886+ ( ) =>
1887+ Temporal . Duration . from ( 'P1M280D' ) . total ( {
1888+ unit : 'month' ,
1889+ relativeTo : { year : 2021 , month : 11 , day : 26 , offset : '+088:00' , timeZone : 'Europe/London' }
1890+ } ) ,
1891+ RangeError
1892+ ) ;
1893+ } ) ;
18561894 } ) ;
18571895 describe ( 'Duration.compare' , ( ) => {
18581896 describe ( 'time units only' , ( ) => {
@@ -1949,6 +1987,15 @@ describe('Duration', () => {
19491987 it ( 'does not lose precision when totaling everything down to nanoseconds' , ( ) => {
19501988 notEqual ( Duration . compare ( { days : 200 } , { days : 200 , nanoseconds : 1 } ) , 0 ) ;
19511989 } ) ;
1990+ it ( 'throws with invalid offset in relativeTo' , ( ) => {
1991+ throws ( ( ) => {
1992+ const d1 = Temporal . Duration . from ( 'P1M280D' ) ;
1993+ const d2 = Temporal . Duration . from ( 'P1M281D' ) ;
1994+ Temporal . Duration . compare ( d1 , d2 , {
1995+ relativeTo : { year : 2021 , month : 11 , day : 26 , offset : '+088:00' , timeZone : 'Europe/London' }
1996+ } ) ;
1997+ } , RangeError ) ;
1998+ } ) ;
19521999 } ) ;
19532000} ) ;
19542001
0 commit comments