@@ -976,6 +976,277 @@ describe('#integration examples', () => {
976
976
done ( )
977
977
} )
978
978
} , 60000 )
979
+
980
+ describe ( 'temporal types examples' , ( ) => {
981
+ it ( 'Duration' , async ( ) => {
982
+ const driver = driverGlobal
983
+ const session = driver . session ( )
984
+
985
+ try {
986
+ // tag::temporal-types-duration[]
987
+ // Creating the Duration object
988
+ const duration = new neo4j . types . Duration (
989
+ 3 , // month
990
+ 5 , // days
991
+ 7 , // seconds
992
+ 11 // nano seconds
993
+ )
994
+ // end::temporal-types-duration[]
995
+
996
+ const result = await session . run ( 'RETURN $duration as fieldName' , {
997
+ duration
998
+ } )
999
+
1000
+ const record = result . records [ 0 ]
1001
+
1002
+ // tag::temporal-types-duration[]
1003
+
1004
+ // Getting Duration field from record
1005
+ const durationField = record . get ( 'fieldName' )
1006
+
1007
+ // Verifying if object is a Duration
1008
+ neo4j . isDuration ( durationField ) // true
1009
+
1010
+ // Serializing as ISO String
1011
+ durationField . toString ( ) // P3M5DT7.000000011S
1012
+ // end::temporal-types-duration[]
1013
+
1014
+ expect ( neo4j . isDuration ( durationField ) ) . toEqual ( true )
1015
+ expect ( durationField . months . toInt ( ) ) . toEqual ( duration . months )
1016
+ expect ( durationField . days . toInt ( ) ) . toEqual ( duration . days )
1017
+ expect ( durationField . seconds ) . toEqual ( duration . seconds )
1018
+ expect ( durationField . nanoseconds ) . toEqual ( duration . nanoseconds )
1019
+ } finally {
1020
+ await session . close ( )
1021
+ }
1022
+ } , 30000 )
1023
+
1024
+ it ( 'LocalTime' , async ( ) => {
1025
+ const driver = driverGlobal
1026
+ const session = driver . session ( )
1027
+ const standardDate = new Date ( )
1028
+
1029
+ try {
1030
+ // tag::temporal-types-localtime[]
1031
+ // Creating LocalTime from standard javascript Date.
1032
+ // Alternatively, the LocalTime could be created with
1033
+ // new neo4j.types.LocalTime(hour, minute, second, nanosecond)
1034
+ const localTime = neo4j . types . LocalTime . fromStandardDate (
1035
+ standardDate ,
1036
+ 200 // nanosecond (optional)
1037
+ )
1038
+ // end::temporal-types-localtime[]
1039
+
1040
+ const result = await session . run ( 'RETURN $localTime as fieldName' , {
1041
+ localTime
1042
+ } )
1043
+
1044
+ const record = result . records [ 0 ]
1045
+
1046
+ // tag::temporal-types-localtime[]
1047
+
1048
+ // Getting LocalTime field from record
1049
+ const fieldLocalTime = record . get ( 'fieldName' )
1050
+
1051
+ // Verifying if object is a LocalTime
1052
+ neo4j . isLocalTime ( fieldLocalTime ) // true
1053
+
1054
+ // Serializing as ISO String
1055
+ fieldLocalTime . toString ( ) // 13:40:38.539000200
1056
+ // end::temporal-types-localtime[]
1057
+
1058
+ expect ( neo4j . isLocalTime ( fieldLocalTime ) ) . toBe ( true )
1059
+ expect ( fieldLocalTime . hour . toInt ( ) ) . toEqual ( localTime . hour )
1060
+ expect ( fieldLocalTime . minute . toInt ( ) ) . toEqual ( localTime . minute )
1061
+ expect ( fieldLocalTime . second . toInt ( ) ) . toEqual ( localTime . second )
1062
+ expect ( fieldLocalTime . nanosecond . toInt ( ) ) . toEqual ( localTime . nanosecond )
1063
+ } finally {
1064
+ await session . close ( )
1065
+ }
1066
+ } , 30000 )
1067
+
1068
+ it ( 'Time' , async ( ) => {
1069
+ const driver = driverGlobal
1070
+ const session = driver . session ( )
1071
+ const standardDate = new Date ( )
1072
+
1073
+ try {
1074
+ // tag::temporal-types-time[]
1075
+ // Creating Time from standard javascript Date.
1076
+ // Alternatively, the Time could be created with
1077
+ // new neo4j.types.Time(hour, minute, second, nanosecond, timeZoneOffsetSeconds)
1078
+ const time = neo4j . types . Time . fromStandardDate (
1079
+ standardDate ,
1080
+ 200 // nanosecond (optional)
1081
+ )
1082
+ // end::temporal-types-time[]
1083
+
1084
+ const result = await session . run ( 'RETURN $time as fieldName' , { time } )
1085
+
1086
+ const record = result . records [ 0 ]
1087
+
1088
+ // tag::temporal-types-time[]
1089
+
1090
+ // Getting Time field from record
1091
+ const fieldTime = record . get ( 'fieldName' )
1092
+
1093
+ // Verifying if object is a Time
1094
+ neo4j . isTime ( fieldTime ) // true
1095
+
1096
+ // Serializing as ISO String
1097
+ fieldTime . toString ( ) // 13:39:08.529000200+02:00
1098
+ // end::temporal-types-time[]
1099
+
1100
+ expect ( neo4j . isTime ( fieldTime ) ) . toBe ( true )
1101
+ expect ( fieldTime . hour . toInt ( ) ) . toEqual ( time . hour )
1102
+ expect ( fieldTime . minute . toInt ( ) ) . toEqual ( time . minute )
1103
+ expect ( fieldTime . second . toInt ( ) ) . toEqual ( time . second )
1104
+ expect ( fieldTime . nanosecond . toInt ( ) ) . toEqual ( time . nanosecond )
1105
+ expect ( fieldTime . timeZoneOffsetSeconds . toInt ( ) ) . toEqual (
1106
+ time . timeZoneOffsetSeconds
1107
+ )
1108
+ } finally {
1109
+ await session . close ( )
1110
+ }
1111
+ } , 30000 )
1112
+
1113
+ it ( 'Date' , async ( ) => {
1114
+ const driver = driverGlobal
1115
+ const session = driver . session ( )
1116
+ const standardDate = new Date ( )
1117
+
1118
+ try {
1119
+ // tag::temporal-types-date[]
1120
+ // Creating Date from standard javascript Date.
1121
+ // Alternatively, the Date could be created with
1122
+ // new neo4j.types.Date(year, month, day)
1123
+ const date = neo4j . types . Date . fromStandardDate ( standardDate )
1124
+ // end::temporal-types-date[]
1125
+
1126
+ const result = await session . run ( 'RETURN $date as fieldName' , { date } )
1127
+
1128
+ const record = result . records [ 0 ]
1129
+
1130
+ // tag::temporal-types-date[]
1131
+
1132
+ // Getting Date field from record
1133
+ const fieldDate = record . get ( 'fieldName' )
1134
+
1135
+ // Verifying if object is a Date
1136
+ neo4j . isDate ( fieldDate ) // true
1137
+
1138
+ // Serializing as ISO String
1139
+ fieldDate . toString ( ) // 2021-06-07
1140
+ // end::temporal-types-date[]
1141
+
1142
+ expect ( neo4j . isDate ( fieldDate ) ) . toBe ( true )
1143
+ expect ( fieldDate . year . toInt ( ) ) . toEqual ( date . year )
1144
+ expect ( fieldDate . month . toInt ( ) ) . toEqual ( date . month )
1145
+ expect ( fieldDate . day . toInt ( ) ) . toEqual ( date . day )
1146
+ } finally {
1147
+ await session . close ( )
1148
+ }
1149
+ } , 30000 )
1150
+
1151
+ it ( 'LocalDateTime' , async ( ) => {
1152
+ const driver = driverGlobal
1153
+ const session = driver . session ( )
1154
+ const standardDate = new Date ( )
1155
+
1156
+ try {
1157
+ // tag::temporal-types-localdatetime[]
1158
+ // Creating LocalDateTime from standard javascript Date.
1159
+ // Alternatively, the LocalDateTime could be created with
1160
+ // new neo4j.types.LocalDateTime(year, month, day, hour, minute, second, nanosecond)
1161
+ const localDateTime = neo4j . types . LocalDateTime . fromStandardDate (
1162
+ standardDate ,
1163
+ 200 // nanosecond (optional)
1164
+ )
1165
+ // end::temporal-types-localdatetime[]
1166
+
1167
+ const result = await session . run ( 'RETURN $localDateTime as fieldName' , {
1168
+ localDateTime
1169
+ } )
1170
+
1171
+ const record = result . records [ 0 ]
1172
+
1173
+ // tag::temporal-types-localdatetime[]
1174
+
1175
+ // Getting LocalDateTime field from record
1176
+ const fieldLocalDateTime = record . get ( 'fieldName' )
1177
+
1178
+ // Verifying if object is a LocalDateTime
1179
+ neo4j . isLocalDateTime ( fieldLocalDateTime ) // true
1180
+
1181
+ // Serializing as ISO String
1182
+ fieldLocalDateTime . toString ( ) // 2021-06-07T13:35:46.344000200
1183
+ // end::temporal-types-localdatetime[]
1184
+
1185
+ expect ( neo4j . isLocalDateTime ( fieldLocalDateTime ) ) . toBe ( true )
1186
+ expect ( fieldLocalDateTime . year . toInt ( ) ) . toEqual ( localDateTime . year )
1187
+ expect ( fieldLocalDateTime . month . toInt ( ) ) . toEqual ( localDateTime . month )
1188
+ expect ( fieldLocalDateTime . day . toInt ( ) ) . toEqual ( localDateTime . day )
1189
+ expect ( fieldLocalDateTime . hour . toInt ( ) ) . toEqual ( localDateTime . hour )
1190
+ expect ( fieldLocalDateTime . minute . toInt ( ) ) . toEqual ( localDateTime . minute )
1191
+ expect ( fieldLocalDateTime . second . toInt ( ) ) . toEqual ( localDateTime . second )
1192
+ expect ( fieldLocalDateTime . nanosecond . toInt ( ) ) . toEqual (
1193
+ localDateTime . nanosecond
1194
+ )
1195
+ } finally {
1196
+ await session . close ( )
1197
+ }
1198
+ } , 30000 )
1199
+
1200
+ it ( 'DateTime' , async ( ) => {
1201
+ const driver = driverGlobal
1202
+ const session = driver . session ( )
1203
+ const standardDate = new Date ( )
1204
+
1205
+ try {
1206
+ // tag::temporal-types-datetime[]
1207
+ // Creating DateTime from standard javascript Date.
1208
+ // Alternatively, the DateTime could be created with
1209
+ // new neo4j.types.DateTime(year, month, day, hour, minute, second, nanosecond, timeZoneOffsetSeconds)
1210
+ const dateTime = neo4j . types . DateTime . fromStandardDate (
1211
+ standardDate ,
1212
+ 200 // nanosecond (optional)
1213
+ )
1214
+ // end::temporal-types-datetime[]
1215
+
1216
+ const result = await session . run ( 'RETURN $dateTime as fieldName' , {
1217
+ dateTime
1218
+ } )
1219
+
1220
+ const record = result . records [ 0 ]
1221
+
1222
+ // tag::temporal-types-datetime[]
1223
+
1224
+ // Getting DateTime field from record
1225
+ const fieldDateTime = record . get ( 'fieldName' )
1226
+
1227
+ // Verifying if object is a DateTime
1228
+ neo4j . isDateTime ( fieldDateTime ) // true
1229
+
1230
+ // Serializing as ISO String
1231
+ fieldDateTime . toString ( ) // 2021-06-07T13:33:48.788000200+02:00
1232
+ // end::temporal-types-datetime[]
1233
+
1234
+ expect ( neo4j . isDateTime ( fieldDateTime ) ) . toBe ( true )
1235
+ expect ( fieldDateTime . year . toInt ( ) ) . toEqual ( dateTime . year )
1236
+ expect ( fieldDateTime . month . toInt ( ) ) . toEqual ( dateTime . month )
1237
+ expect ( fieldDateTime . day . toInt ( ) ) . toEqual ( dateTime . day )
1238
+ expect ( fieldDateTime . hour . toInt ( ) ) . toEqual ( dateTime . hour )
1239
+ expect ( fieldDateTime . minute . toInt ( ) ) . toEqual ( dateTime . minute )
1240
+ expect ( fieldDateTime . second . toInt ( ) ) . toEqual ( dateTime . second )
1241
+ expect ( fieldDateTime . nanosecond . toInt ( ) ) . toEqual ( dateTime . nanosecond )
1242
+ expect ( fieldDateTime . timeZoneOffsetSeconds . toInt ( ) ) . toEqual (
1243
+ dateTime . timeZoneOffsetSeconds
1244
+ )
1245
+ } finally {
1246
+ await session . close ( )
1247
+ }
1248
+ } , 30000 )
1249
+ } )
979
1250
} )
980
1251
981
1252
function removeLineBreaks ( string ) {
0 commit comments