@@ -524,6 +524,33 @@ describe('temporal-types', () => {
524524 expect ( zonedDateTime . nanosecond ) . toEqual ( neo4j . int ( 9346458 ) ) ;
525525 } ) ;
526526
527+ it ( 'should format duration to string' , done => {
528+ if ( neo4jDoesNotSupportTemporalTypes ( done ) ) {
529+ return ;
530+ }
531+
532+ testDurationToString ( [
533+ { duration : duration ( 0 , 0 , 1 , 0 ) , expectedString : 'P0M0DT1S' } ,
534+ { duration : duration ( 0 , 0 , - 1 , 0 ) , expectedString : 'P0M0DT-1S' } ,
535+
536+ { duration : duration ( 0 , 0 , 0 , 5 ) , expectedString : 'P0M0DT0.000000005S' } ,
537+ { duration : duration ( 0 , 0 , 0 , - 5 ) , expectedString : 'P0M0DT-0.000000005S' } ,
538+ { duration : duration ( 0 , 0 , 0 , 999999999 ) , expectedString : 'P0M0DT0.999999999S' } ,
539+ { duration : duration ( 0 , 0 , 0 , - 999999999 ) , expectedString : 'P0M0DT-0.999999999S' } ,
540+
541+ { duration : duration ( 0 , 0 , 1 , 5 ) , expectedString : 'P0M0DT1.000000005S' } ,
542+ { duration : duration ( 0 , 0 , - 1 , - 5 ) , expectedString : 'P0M0DT-1.000000005S' } ,
543+ { duration : duration ( 0 , 0 , 1 , - 5 ) , expectedString : 'P0M0DT0.999999995S' } ,
544+ { duration : duration ( 0 , 0 , - 1 , 5 ) , expectedString : 'P0M0DT-0.999999995S' } ,
545+ { duration : duration ( 0 , 0 , 1 , 999999999 ) , expectedString : 'P0M0DT1.999999999S' } ,
546+ { duration : duration ( 0 , 0 , - 1 , - 999999999 ) , expectedString : 'P0M0DT-1.999999999S' } ,
547+ { duration : duration ( 0 , 0 , 1 , - 999999999 ) , expectedString : 'P0M0DT0.000000001S' } ,
548+ { duration : duration ( 0 , 0 , - 1 , 999999999 ) , expectedString : 'P0M0DT-0.000000001S' } ,
549+
550+ { duration : duration ( 0 , 0 , - 78036 , - 143000000 ) , expectedString : 'P0M0DT-78036.143000000S' }
551+ ] , done ) ;
552+ } ) ;
553+
527554 function testSendAndReceiveRandomTemporalValues ( valueGenerator , done ) {
528555 const asyncFunction = ( index , callback ) => {
529556 const next = ( ) => callback ( ) ;
@@ -578,6 +605,22 @@ describe('temporal-types', () => {
578605 } ) ;
579606 }
580607
608+ function testDurationToString ( values , done ) {
609+ const durations = values . map ( value => value . duration ) ;
610+ const expectedDurationStrings = values . map ( value => value . expectedString ) ;
611+
612+ session . run ( 'UNWIND $durations AS d RETURN d' , { durations : durations } ) . then ( result => {
613+ const receivedDurationStrings = result . records
614+ . map ( record => record . get ( 0 ) )
615+ . map ( duration => duration . toString ( ) ) ;
616+
617+ expect ( expectedDurationStrings ) . toEqual ( receivedDurationStrings ) ;
618+ done ( ) ;
619+ } ) . catch ( error => {
620+ done . fail ( error ) ;
621+ } ) ;
622+ }
623+
581624 function neo4jDoesNotSupportTemporalTypes ( done ) {
582625 if ( serverVersion . compareTo ( VERSION_3_4_0 ) < 0 ) {
583626 done ( ) ;
0 commit comments