Permalink
Browse files

Support timezones in Cron schedule builder DSL

  • Loading branch information...
1 parent 856baa1 commit 7fe132b948dbc514ef4ec92e209bd5319885198d @michaelklishin michaelklishin committed Dec 29, 2011
@@ -1,6 +1,7 @@
(ns clojurewerkz.quartzite.schedule.cron
(:import [org.quartz CronScheduleBuilder]
- [org.quartz.spi MutableTrigger]))
+ [org.quartz.spi MutableTrigger]
+ [java.util TimeZone]))
(defn cron-schedule
@@ -20,6 +21,11 @@
(CronScheduleBuilder/monthlyOnDayAndHourAndMinute day-of-month hour minute))
+(defn in-time-zone
+ [^CronScheduleBuilder ssb ^TimeZone tz]
+ (.inTimeZone ssb tz))
+
+
(defn finalize
[^CronScheduleBuilder ssb]
(.build ssb))
@@ -5,15 +5,18 @@
[clj-time.core :only [date-time]])
(:import [org.quartz CronScheduleBuilder DateBuilder]
[org.quartz.impl.triggers CronTriggerImpl]
- [org.joda.time DateTime]))
+ [org.joda.time DateTime]
+ [java.util TimeZone]))
(deftest test-cron-schedule-dsl-example1
(let [s "0 0 3 15 * ?"
^DateTime d1 (date-time 2012 2 15 3)
^DateTime d2 (date-time 2012 2 16 3)
+ ^TimeZone tz (TimeZone/getTimeZone "Europe/Moscow")
^CronTriggerImpl sched (schedule
(cron-schedule s)
+ (in-time-zone tz)
(finalize))]
(is (= s (.getCronExpression sched)))
(is (.willFireOn sched (.toCalendar d1 nil) true))

0 comments on commit 7fe132b

Please sign in to comment.