@@ -88,8 +88,9 @@ public double toYears(
88
88
}
89
89
90
90
@ UserFunction ("apoc.date.fields" )
91
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_5 )
91
92
@ Description ("Splits the given date into fields returning a `MAP` containing the values of each field." )
92
- public Map <String , Object > fields (
93
+ public Map <String , Object > fieldsCypher5 (
93
94
final @ Name (value = "date" , description = "A string representation of a temporal value." ) String date ,
94
95
final @ Name (
95
96
value = "pattern" ,
@@ -109,6 +110,30 @@ public Map<String, Object> fields(
109
110
return result .asMap ();
110
111
}
111
112
113
+ @ Deprecated
114
+ @ UserFunction (value = "apoc.date.fields" , deprecatedBy = "Cypher's temporal pattern constructors." )
115
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
116
+ @ Description ("Splits the given date into fields returning a `MAP` containing the values of each field." )
117
+ public Map <String , Object > fields (
118
+ final @ Name (value = "date" , description = "A string representation of a temporal value." ) String date ,
119
+ final @ Name (
120
+ value = "pattern" ,
121
+ defaultValue = DEFAULT_FORMAT ,
122
+ description = "The format the given temporal is formatted as." ) String pattern ) {
123
+ if (date == null ) {
124
+ return Util .map ();
125
+ }
126
+ DateTimeFormatter fmt = getSafeDateTimeFormatter (pattern );
127
+ TemporalAccessor temporal = fmt .parse (date );
128
+ FieldResult result = new FieldResult ();
129
+
130
+ for (final TemporalQuery <Consumer <FieldResult >> query : DT_FIELDS_SELECTORS ) {
131
+ query .queryFrom (temporal ).accept (result );
132
+ }
133
+
134
+ return result .asMap ();
135
+ }
136
+
112
137
@ UserFunction ("apoc.date.field" )
113
138
@ QueryLanguageScope (scope = {QueryLanguage .CYPHER_5 })
114
139
@ Description ("Returns the value of one field from the given date time." )
@@ -278,8 +303,9 @@ 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 )
281
307
@ Description ("Parses the given date `STRING` from a specified format into the specified time unit." )
282
- public Long parse (
308
+ public Long parseCypher5 (
283
309
@ Name (value = "time" , description = "The datetime to convert." ) String time ,
284
310
@ Name (value = "unit" , defaultValue = "ms" , description = "The conversion unit." ) String unit ,
285
311
@ Name (value = "format" , defaultValue = DEFAULT_FORMAT , description = "The format the given datetime is in." )
@@ -290,6 +316,21 @@ public Long parse(
290
316
return value == null ? null : unit (unit ).convert (value , TimeUnit .MILLISECONDS );
291
317
}
292
318
319
+ @ Deprecated
320
+ @ UserFunction (value = "apoc.date.parse" , deprecatedBy = "Cypher's temporal pattern constructors." )
321
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
322
+ @ Description ("Parses the given date `STRING` from a specified format into the specified time unit." )
323
+ public Long parse (
324
+ @ Name (value = "time" , description = "The datetime to convert." ) String time ,
325
+ @ Name (value = "unit" , defaultValue = "ms" , description = "The conversion unit." ) String unit ,
326
+ @ Name (value = "format" , defaultValue = DEFAULT_FORMAT , description = "The format the given datetime is in." )
327
+ String format ,
328
+ final @ Name (value = "timezone" , defaultValue = "" , description = "The timezone the given datetime is in." )
329
+ String timezone ) {
330
+ Long value = StringUtils .isBlank (time ) ? null : parseOrThrow (time , getFormat (format , timezone ));
331
+ return value == null ? null : unit (unit ).convert (value , TimeUnit .MILLISECONDS );
332
+ }
333
+
293
334
@ UserFunction ("apoc.date.systemTimezone" )
294
335
@ Description ("Returns the display name of the system time zone (e.g. Europe/London)." )
295
336
public String systemTimezone () {
@@ -306,8 +347,9 @@ public Long convert(
306
347
}
307
348
308
349
@ UserFunction ("apoc.date.convertFormat" )
350
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_5 )
309
351
@ Description ("Converts a `STRING` of one type of date format into a `STRING` of another type of date format." )
310
- public String convertFormat (
352
+ public String convertFormatCypher5 (
311
353
@ Name (value = "temporal" , description = "A string representation of a temporal value." ) String input ,
312
354
@ Name (value = "currentFormat" , description = "The format the given temporal is formatted as." )
313
355
String currentFormat ,
@@ -326,6 +368,29 @@ public String convertFormat(
326
368
return convertToFormatter .format (currentFormatter .parse (input ));
327
369
}
328
370
371
+ @ Deprecated
372
+ @ UserFunction (value = "apoc.date.convertFormat" , deprecatedBy = "Cypher's temporal pattern constructors and format() function." )
373
+ @ QueryLanguageScope (scope = QueryLanguage .CYPHER_25 )
374
+ @ Description ("Converts a `STRING` of one type of date format into a `STRING` of another type of date format." )
375
+ public String convertFormat (
376
+ @ Name (value = "temporal" , description = "A string representation of a temporal value." ) String input ,
377
+ @ Name (value = "currentFormat" , description = "The format the given temporal is formatted as." )
378
+ String currentFormat ,
379
+ @ Name (
380
+ value = "convertTo" ,
381
+ defaultValue = "yyyy-MM-dd" ,
382
+ description = "The format to convert the given temporal value to." )
383
+ String convertTo ) {
384
+ if (input == null || input .isEmpty ()) {
385
+ return null ;
386
+ }
387
+
388
+ DateTimeFormatter currentFormatter = DateFormatUtil .getOrCreate (currentFormat );
389
+ DateTimeFormatter convertToFormatter = DateFormatUtil .getOrCreate (convertTo );
390
+
391
+ return convertToFormatter .format (currentFormatter .parse (input ));
392
+ }
393
+
329
394
@ UserFunction ("apoc.date.add" )
330
395
@ Description ("Adds a unit of specified time to the given timestamp." )
331
396
public Long add (
0 commit comments