@@ -88,6 +88,31 @@ public double toYears(
88
88
}
89
89
90
90
@ UserFunction ("apoc.date.fields" )
91
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_5 )
92
+ @ Description ("Splits the given date into fields returning a `MAP` containing the values of each field." )
93
+ public Map <String , Object > fieldsCypher5 (
94
+ final @ Name (value = "date" , description = "A string representation of a temporal value." ) String date ,
95
+ final @ Name (
96
+ value = "pattern" ,
97
+ defaultValue = DEFAULT_FORMAT ,
98
+ description = "The format the given temporal is formatted as." ) String pattern ) {
99
+ if (date == null ) {
100
+ return Util .map ();
101
+ }
102
+ DateTimeFormatter fmt = getSafeDateTimeFormatter (pattern );
103
+ TemporalAccessor temporal = fmt .parse (date );
104
+ FieldResult result = new FieldResult ();
105
+
106
+ for (final TemporalQuery <Consumer <FieldResult >> query : DT_FIELDS_SELECTORS ) {
107
+ query .queryFrom (temporal ).accept (result );
108
+ }
109
+
110
+ return result .asMap ();
111
+ }
112
+
113
+ @ Deprecated
114
+ @ UserFunction (value = "apoc.date.fields" , deprecatedBy = "Cypher's temporal pattern constructors." )
115
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
91
116
@ Description ("Splits the given date into fields returning a `MAP` containing the values of each field." )
92
117
public Map <String , Object > fields (
93
118
final @ Name (value = "date" , description = "A string representation of a temporal value." ) String date ,
@@ -278,6 +303,22 @@ public Long fromISO8601(final @Name(value = "time", description = "The datetime
278
303
}
279
304
280
305
@ UserFunction ("apoc.date.parse" )
306
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_5 )
307
+ @ Description ("Parses the given date `STRING` from a specified format into the specified time unit." )
308
+ public Long parseCypher5 (
309
+ @ Name (value = "time" , description = "The datetime to convert." ) String time ,
310
+ @ Name (value = "unit" , defaultValue = "ms" , description = "The conversion unit." ) String unit ,
311
+ @ Name (value = "format" , defaultValue = DEFAULT_FORMAT , description = "The format the given datetime is in." )
312
+ String format ,
313
+ final @ Name (value = "timezone" , defaultValue = "" , description = "The timezone the given datetime is in." )
314
+ String timezone ) {
315
+ Long value = StringUtils .isBlank (time ) ? null : parseOrThrow (time , getFormat (format , timezone ));
316
+ return value == null ? null : unit (unit ).convert (value , TimeUnit .MILLISECONDS );
317
+ }
318
+
319
+ @ Deprecated
320
+ @ UserFunction (value = "apoc.date.parse" , deprecatedBy = "Cypher's temporal pattern constructors." )
321
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
281
322
@ Description ("Parses the given date `STRING` from a specified format into the specified time unit." )
282
323
public Long parse (
283
324
@ Name (value = "time" , description = "The datetime to convert." ) String time ,
@@ -306,6 +347,32 @@ public Long convert(
306
347
}
307
348
308
349
@ UserFunction ("apoc.date.convertFormat" )
350
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_5 )
351
+ @ Description ("Converts a `STRING` of one type of date format into a `STRING` of another type of date format." )
352
+ public String convertFormatCypher5 (
353
+ @ Name (value = "temporal" , description = "A string representation of a temporal value." ) String input ,
354
+ @ Name (value = "currentFormat" , description = "The format the given temporal is formatted as." )
355
+ String currentFormat ,
356
+ @ Name (
357
+ value = "convertTo" ,
358
+ defaultValue = "yyyy-MM-dd" ,
359
+ description = "The format to convert the given temporal value to." )
360
+ String convertTo ) {
361
+ if (input == null || input .isEmpty ()) {
362
+ return null ;
363
+ }
364
+
365
+ DateTimeFormatter currentFormatter = DateFormatUtil .getOrCreate (currentFormat );
366
+ DateTimeFormatter convertToFormatter = DateFormatUtil .getOrCreate (convertTo );
367
+
368
+ return convertToFormatter .format (currentFormatter .parse (input ));
369
+ }
370
+
371
+ @ Deprecated
372
+ @ UserFunction (
373
+ value = "apoc.date.convertFormat" ,
374
+ deprecatedBy = "Cypher's temporal pattern constructors and format() function." )
375
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
309
376
@ Description ("Converts a `STRING` of one type of date format into a `STRING` of another type of date format." )
310
377
public String convertFormat (
311
378
@ Name (value = "temporal" , description = "A string representation of a temporal value." ) String input ,
0 commit comments