Skip to content

Commit

Permalink
Change time argument list from var-args to explicit args
Browse files Browse the repository at this point in the history
This makes the usage of time clearer and more self documenting, and less
error prone. It also updates the docstring with guidance on arg types.

Fixes apa512#87
  • Loading branch information
danielcompton committed Oct 12, 2015
1 parent 8fe19e0 commit b6a4459
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. This change
- Update docstring for `rethinkdb.query/without`.
- Update arity and docstring for `rethinkdb.query/merge` to support merging any number of objects.
- Add new arity to `rethinkdb.query/index-create` to allow creating simple indexes from field names. [#86](https://github.com/apa512/clj-rethinkdb/pull/86)
- Update `rethinkdb.query/time` arity to only allow 3, 4, 6, and 7 arguments. Also update docstring to make usage clearer. This was already enforced on the server, but will now be enforced by the client library too. [#87](https://github.com/apa512/clj-rethinkdb/issues/87)

## [0.10.1] - 2015-07-08
### Added
Expand Down
26 changes: 19 additions & 7 deletions src/rethinkdb/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,25 @@
(term :NOW []))

(defn time
"Create a time object for a specific time."
[& date-time-parts]
(let [args (concat date-time-parts
(if (string? (last date-time-parts))
[]
["+00:00"]))]
(term :TIME args)))
"Create a time object for a specific time.
- year is an integer between 1400 and 9999.
- month is an integer between 1 and 12.
- day is an integer between 1 and 31.
- hour is an integer.
- minutes is an integer.
- seconds is a double. Its value will be rounded to three decimal places (millisecond-precision).
timezone can be 'Z' (for UTC) or a string with the format ±[hh]:[mm].
If tz is not supplied then UTC is used."
([year month day]
(time year month day "Z"))
([year month day tz]
(term :TIME [year month day tz]))
([year month day hour minute second]
(time year month day hour minute second "Z"))
([year month day hour minute second tz]
(term :TIME [year month day hour minute second tz])))

(defn epoch-time
"Create a time object based on seconds since epoch. The first argument is a
Expand Down
3 changes: 3 additions & 0 deletions test/rethinkdb/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
(r/minutes (r/time 2014 12 31 10 4 5)) 4
(r/seconds (r/time 2014 12 31 10 4 5)) 5
(r/to-iso8601 (r/time 2014 12 31)) "2014-12-31T00:00:00+00:00"
(r/to-iso8601 (r/time 2014 12 31 "+02:00")) "2014-12-31T00:00:00+02:00"
(r/to-iso8601 (r/time 2014 12 31 14 12 33)) "2014-12-31T14:12:33+00:00"
(r/to-iso8601 (r/time 2014 12 31 14 12 33 "-04:00")) "2014-12-31T14:12:33-04:00"
(r/to-epoch-time (r/time 1970 1 1)) 0)))

(deftest control-structure
Expand Down

0 comments on commit b6a4459

Please sign in to comment.