Skip to content

Commit 7877c2f

Browse files
Temporal Parse deprecations
1 parent 93239a8 commit 7877c2f

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

core/src/main/java/apoc/date/Date.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,31 @@ public double toYears(
8888
}
8989

9090
@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)
91116
@Description("Splits the given date into fields returning a `MAP` containing the values of each field.")
92117
public Map<String, Object> fields(
93118
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
278303
}
279304

280305
@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)
281322
@Description("Parses the given date `STRING` from a specified format into the specified time unit.")
282323
public Long parse(
283324
@Name(value = "time", description = "The datetime to convert.") String time,
@@ -306,6 +347,32 @@ public Long convert(
306347
}
307348

308349
@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)
309376
@Description("Converts a `STRING` of one type of date format into a `STRING` of another type of date format.")
310377
public String convertFormat(
311378
@Name(value = "temporal", description = "A string representation of a temporal value.") String input,

core/src/main/java/apoc/temporal/TemporalProcedures.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ public String formatDuration(
157157
}
158158

159159
@UserFunction("apoc.temporal.toZonedTemporal")
160+
@QueryLanguageScope(scope = QueryLanguage.CYPHER_5)
161+
@Description("Parses the given date `STRING` using the specified format into the given time zone.")
162+
public ZonedDateTime toZonedTemporalCypher5(
163+
@Name(value = "time", description = "The date string to be parsed.") String time,
164+
@Name(value = "format", defaultValue = DEFAULT_FORMAT, description = "The format of the given date string.")
165+
String format,
166+
final @Name(value = "timezone", defaultValue = "UTC", description = "The timezone the given string is in.")
167+
String timezone) {
168+
Long value = parseOrThrow(time, getFormat(format, timezone));
169+
return value == null ? null : Instant.ofEpochMilli(value).atZone(ZoneId.of(timezone));
170+
}
171+
172+
@Deprecated
173+
@UserFunction(value = "apoc.temporal.toZonedTemporal", deprecatedBy = "Cypher's temporal pattern constructors.")
174+
@QueryLanguageScope(scope = QueryLanguage.CYPHER_25)
160175
@Description("Parses the given date `STRING` using the specified format into the given time zone.")
161176
public ZonedDateTime toZonedTemporal(
162177
@Name(value = "time", description = "The date string to be parsed.") String time,

0 commit comments

Comments
 (0)