Date { @UserFunction @Description("apoc.date.fields('2012-12-23',('yyyy-MM-dd')) - return columns and a map representation of date parsed with the given format with entries for years,months,weekdays,days,hours,minutes,seconds,zoneid") public Map<String,Object> fields(final @Name("date") String date, final @Name(value = "pattern", defaultValue = DEFAULT_FORMAT) String pattern) { if (date == null) { return Util.map(); } DateTimeFormatter fmt = getSafeDateTimeFormatter(pattern); TemporalAccessor temporal = fmt.parse(date); FieldResult result = new FieldResult(); for (final TemporalQuery<Consumer<FieldResult>> query : DT_FIELDS_SELECTORS) { query.queryFrom(temporal).accept(result); } return result.asMap(); }  @UserFunction @Description("toYears(timestamp) or toYears(date[,format]) converts timestamp into floating point years") double toYears(@Name("value") Object value, @Name(value = "format", defaultValue = DEFAULT_FORMAT) String format); @UserFunction @Description("apoc.date.fields('2012-12-23',('yyyy-MM-dd')) - return columns and a map representation of date parsed with the given format with entries for years,months,weekdays,days,hours,minutes,seconds,zoneid") Map<String,Object> fields(final @Name("date") String date, final @Name(value = "pattern", defaultValue = DEFAULT_FORMAT) String pattern); @UserFunction @Description("apoc.date.field(12345,('ms|s|m|h|d|month|year'),('TZ')") Long field(final @Name("time") Long time,  @Name(value = "unit", defaultValue = "d") String unit, @Name(value = "timezone",defaultValue = "UTC") String timezone); @UserFunction @Description( "apoc.date.currentTimestamp() - returns System.currentTimeMillis()" ) long currentTimestamp(); static TimeUnit unit(String unit); @UserFunction @Description("apoc.date.format(12345,('ms|s|m|h|d'),('yyyy-MM-dd HH:mm:ss zzz'),('TZ')) get string representation of time value optionally using the specified unit (default ms) using specified format (default ISO) and specified time zone (default current TZ)") String format(final @Name("time") Long time, @Name(value = "unit", defaultValue = "ms") String unit, @Name(value = "format",defaultValue = DEFAULT_FORMAT) String format, @Name(value = "timezone",defaultValue = "") String timezone); @UserFunction @Description("apoc.date.toISO8601(12345,('ms|s|m|h|d') return string representation of time in ISO8601 format") String toISO8601(final @Name("time") Long time, @Name(value = "unit", defaultValue = "ms") String unit); @UserFunction @Description("apoc.date.fromISO8601('yyyy-MM-ddTHH:mm:ss.SSSZ') return number representation of time in EPOCH format") Long fromISO8601(final @Name("time") String time); @UserFunction @Description("apoc.date.parse('2012-12-23','ms|s|m|h|d','yyyy-MM-dd') parse date string using the specified format into the specified time unit") Long parse(@Name("time") String time, @Name(value = "unit", defaultValue = "ms") String unit, @Name(value = "format",defaultValue = DEFAULT_FORMAT) String format, final @Name(value = "timezone", defaultValue = "") String timezone); @UserFunction(deprecatedBy = "apoc.temporal.toZonedTemporal") @Description("apoc.date.parseAsZonedDateTime('2012-12-23 23:59:59','yyyy-MM-dd HH:mm:ss', 'UTC-hour-offset') parse date string using the specified format to specified timezone") @Deprecated ZonedDateTime parseAsZonedDateTime(@Name("time") String time, @Name(value = "format", defaultValue = DEFAULT_FORMAT) String format, final @Name(value = "timezone", defaultValue = "UTC") String timezone); @UserFunction @Description("apoc.date.systemTimezone() returns the system timezone display name") String systemTimezone(); @UserFunction @Description("apoc.date.convert(12345, 'ms', 'd') convert a timestamp in one time unit into one of a different time unit") Long convert(@Name("time") long time, @Name(value = "unit") String unit, @Name(value = "toUnit") String toUnit); @UserFunction @Description("apoc.date.convertFormat('Tue, 14 May 2019 14:52:06 -0400', 'rfc_1123_date_time', 'iso_date_time') convert a String of one date format into a String of another date format.") String convertFormat( @Name( "temporal" ) String input, @Name( value = "currentFormat" ) String currentFormat, @Name( value = "convertTo" , defaultValue = "yyyy-MM-dd" ) String convertTo ); @UserFunction @Description("apoc.date.add(12345, 'ms', -365, 'd') given a timestamp in one time unit, adds a value of the specified time unit") Long add(@Name("time") long time, @Name(value = "unit") String unit, @Name(value = "addValue") long addValue, @Name(value = "addUnit") String addUnit); String parse(final @Name("millis") long millis, final @Name(value = "pattern", defaultValue = DEFAULT_FORMAT) String pattern, final @Name("timezone") String timezone); static DateFormat getFormat(final String pattern, final String timezone); static Long parseOrThrow(final String date, final DateFormat format); static final String DEFAULT_FORMAT; }
@Test public void testfields() throws Exception { testCall(db, "RETURN apoc.date.fields('2015-01-02 03:04:05') AS value", row -> { Map<String, Object> map = (Map<String, Object>) row.get("value"); assertEquals(2015L, map.get("years")); assertEquals(1L, map.get("months")); assertEquals(2L, map.get("days")); assertEquals(5L, map.get("weekdays")); assertEquals(3L, map.get("hours")); assertEquals(4L, map.get("minutes")); assertEquals(5L, map.get("seconds")); }); }