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