Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support timezones in Cron schedule builder DSL

  • Loading branch information...
commit 7fe132b948dbc514ef4ec92e209bd5319885198d 1 parent 856baa1
Michael Klishin michaelklishin authored
8 src/clojure/clojurewerkz/quartzite/schedule/cron.clj
... ... @@ -1,6 +1,7 @@
1 1 (ns clojurewerkz.quartzite.schedule.cron
2 2 (:import [org.quartz CronScheduleBuilder]
3   - [org.quartz.spi MutableTrigger]))
  3 + [org.quartz.spi MutableTrigger]
  4 + [java.util TimeZone]))
4 5
5 6
6 7 (defn cron-schedule
@@ -20,6 +21,11 @@
20 21 (CronScheduleBuilder/monthlyOnDayAndHourAndMinute day-of-month hour minute))
21 22
22 23
  24 +(defn in-time-zone
  25 + [^CronScheduleBuilder ssb ^TimeZone tz]
  26 + (.inTimeZone ssb tz))
  27 +
  28 +
23 29 (defn finalize
24 30 [^CronScheduleBuilder ssb]
25 31 (.build ssb))
5 test/clojurewerkz/quartzite/test/schedule/cron.clj
@@ -5,15 +5,18 @@
5 5 [clj-time.core :only [date-time]])
6 6 (:import [org.quartz CronScheduleBuilder DateBuilder]
7 7 [org.quartz.impl.triggers CronTriggerImpl]
8   - [org.joda.time DateTime]))
  8 + [org.joda.time DateTime]
  9 + [java.util TimeZone]))
9 10
10 11
11 12 (deftest test-cron-schedule-dsl-example1
12 13 (let [s "0 0 3 15 * ?"
13 14 ^DateTime d1 (date-time 2012 2 15 3)
14 15 ^DateTime d2 (date-time 2012 2 16 3)
  16 + ^TimeZone tz (TimeZone/getTimeZone "Europe/Moscow")
15 17 ^CronTriggerImpl sched (schedule
16 18 (cron-schedule s)
  19 + (in-time-zone tz)
17 20 (finalize))]
18 21 (is (= s (.getCronExpression sched)))
19 22 (is (.willFireOn sched (.toCalendar d1 nil) true))

0 comments on commit 7fe132b

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