Skip to content
Browse files

Added the add method.

  • Loading branch information...
1 parent 72fcb1c commit fab179232259b9ec391ee13f09cc53661ac1094f @waratuman committed Apr 10, 2010
Showing with 13 additions and 0 deletions.
  1. +7 −0 src/clj/date_utils/core.clj
  2. +6 −0 test/date_utils/core_test.clj
View
7 src/clj/date_utils/core.clj
@@ -47,6 +47,13 @@
(defn seconds [cal]
(.get cal GregorianCalendar/SECOND))
+(defn add [cal a]
+ "Add `a` seconds ot the date `cal`. For example
+ `(add (date 2009 1 1) 3600)`."
+ (let [c (.clone cal)]
+ (.add c GregorianCalendar/SECOND a)
+ c))
+
(defn difference [a b]
"The number of seconds that date `a` differs from date `b`. For
example: `(difference (date 2009 1 1) (parse 2009 1 2))` results
View
6 test/date_utils/core_test.clj
@@ -72,6 +72,12 @@
(is (= 49
(seconds (date 1913 2 1 1 20 49)))))
+(deftest add-test
+ (is (= (date 2009 1 2)
+ (add (date 2009 1 1) 86400)))
+ (is (= (date 2009 1 1)
+ (add (date 2009 1 2) -86400))))
+
(deftest difference-test
(is (= 86400
(difference (date 2009 1 1) (date 2009 1 2))))

0 comments on commit fab1792

Please sign in to comment.
Something went wrong with that request. Please try again.