Skip to content

Commit

Permalink
Changed to use double values ands only perform a single pass through …
Browse files Browse the repository at this point in the history
…the relationship list.
  • Loading branch information
InverseFalcon committed Feb 25, 2017
1 parent 1329d6e commit c3f6b59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/datetime.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ endif::env-guide[]
* possible unit values: `ms,s,m,h,d` and their long forms.
* possible time zone values: Either an abbreviation such as `PST`, a full name such as `America/Los_Angeles`, or a custom ID such as `GMT-8:00`. Full names are recommended.

== Conversion of timestamps between different time units

* `apoc.date.convert(12345, 'ms', 'd')` convert a timestamp in one time unit into one of a different time unit

* possible unit values: `ms,s,m,h,d` and their long forms.

== Adding/subtracting time unit values to timestamps

* `apoc.date.add(12345, 'ms', -365, 'd')` given a timestamp in one time unit, adds a value of the specified time unit

* possible unit values: `ms,s,m,h,d` and their long forms.

== Reading separate datetime fields:

Splits date (optionally, using given custom format) into fields returning a map from field name to its value.
Expand Down
12 changes: 12 additions & 0 deletions docs/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,18 @@ Optionally set `apoc.ttl.schedule=5` as repeat frequency.
* possible unit values: `ms,s,m,h,d` and their long forms `millis,milliseconds,seconds,minutes,hours,days`.
* possible time zone values: Either an abbreviation such as `PST`, a full name such as `America/Los_Angeles`, or a custom ID such as `GMT-8:00`. Full names are recommended. You can view a list of full names in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones[this Wikipedia page].

=== Conversion of timestamps between different time units

* `apoc.date.convert(12345, 'ms', 'd')` convert a timestamp in one time unit into one of a different time unit

* possible unit values: `ms,s,m,h,d` and their long forms.

=== Adding/subtracting time unit values to timestamps

* `apoc.date.add(12345, 'ms', -365, 'd')` given a timestamp in one time unit, adds a value of the specified time unit

* possible unit values: `ms,s,m,h,d` and their long forms.

=== Reading separate datetime fields

Splits date (optionally, using given custom format) into fields returning a map from field name to its value.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/apoc/date/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ public String systemTimezone() {
}

@UserFunction
@Description("apoc.date.convert(12345,'ms|s|m|h|d','ms|s|m|h|d') convert a time unit into a different time unit")
@Description("apoc.date.convert(12345, 'ms', 'd') convert a timestamp in one time unit into one of a different time unit")
public Long convert(@Name("time") long time, @Name(value = "unit") String unit, @Name(value = "toUnit") String toUnit) {
return unit(toUnit).convert(time, unit(unit));
}

@UserFunction
@Description("apoc.date.add(12345,'ms|s|m|h|d', 54321, 'ms|s|m|h|d') adds a value of the specified time unit to the original value, outputing in the original value's time unit")
@Description("apoc.date.add(12345, 'ms', -365, 'd') given a timestamp in one time unit, adds a value of the specified time unit")
public Long add(@Name("time") long time, @Name(value = "unit") String unit, @Name(value = "addValue") long addValue, @Name(value = "addUnit") String addUnit) {
long valueToAdd = unit(unit).convert(addValue, unit(addUnit));
return time + valueToAdd;
Expand Down

0 comments on commit c3f6b59

Please sign in to comment.