Daylight savings?

52 views
Skip to first unread message

Jason Marmon

unread,
Jun 10, 2015, 11:19:07 AM6/10/15
to clj-...@googlegroups.com
Is there a simple way using clj-time to account for daylight savings?

If I do (t/hour (t/to-time-zone (t/now) (t/time-zone-for-offset -5))) the time is off by one. Is the idiomatic way just to check the date and if it's within the daylight savings range, adjust the time? Seems like something clj-time might handle.

Sean Corfield

unread,
Jun 10, 2015, 2:12:42 PM6/10/15
to clj-...@googlegroups.com
On Jun 10, 2015, at 3:58 AM, Jason Marmon <jtma...@gmail.com> wrote:
> Is there a simple way using clj-time to account for daylight savings?
>
> If I do (t/hour (t/to-time-zone (t/now) (t/time-zone-for-offset -5))) the time is off by one. Is the idiomatic way just to check the date and if it's within the daylight savings range, adjust the time? Seems like something clj-time might handle.

I don’t see that:

; CIDER 0.8.1 (Java 1.8.0_31, Clojure 1.7.0, nREPL 0.2.6)
user> (require '[clj-time.core :as t])
nil
user> (t/hour (t/to-time-zone (t/now) (t/time-zone-for-offset -5)))
13
user> (t/hour (t/to-time-zone (t/now) (t/time-zone-for-offset -7)))
11
user>

Right now it’s 11:10 here in San Francisco and the West Coast timezone is -7 hours from GMT — see http://www.timeanddate.com/worldclock/usa/san-francisco for that.

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)



Gordon Stratton

unread,
Jun 10, 2015, 4:45:23 PM6/10/15
to clj-...@googlegroups.com
Try `time-zone-for-id` - when you're asking explicitly for an offset,
accounting for daylight saving time doesn't make sense (think about a
situation like with Arizona[1].)

Here's an example:

user=> (require '[clj-time.core :as t])
nil
user=> (t/hour (t/to-time-zone (t/now) (t/time-zone-for-id "America/New_York")))
15
user=> (t/hour (t/to-time-zone (t/now) (t/time-zone-for-offset -5)))
14

[1] http://en.wikipedia.org/wiki/Daylight_saving_time_in_the_United_States#Arizona
> --
> You received this message because you are subscribed to the Google Groups
> "clj-time" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clj-time+u...@googlegroups.com.
> To post to this group, send email to clj-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/clj-time.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages