Skip to content

Commit

Permalink
Fix: LibC.daylight may not be available
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Apr 28, 2016
1 parent c5898fa commit a056f36
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/time/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,23 @@ struct Time

private def self.compute_offset(second)
LibC.tzset
if LibC.daylight == 0
# current TZ doesn't have any DST, neither in past, present or future
offset = -LibC.timezone.to_i64 / 60
else
offset = nil

{% if LibC.methods.includes?("daylight".id) %}
if LibC.daylight == 0
# current TZ doesn't have any DST, neither in past, present or future
offset = -LibC.timezone.to_i64
end
{% end %}

unless offset
# current TZ may have DST, either in past, present or future
ret = LibC.localtime_r(pointerof(second), out tm)
raise Errno.new("localtime_r") if ret.null?
offset = tm.tm_gmtoff.to_i64 / 60
offset = tm.tm_gmtoff.to_i64
end
offset * Span::TicksPerMinute

offset / 60 * Span::TicksPerMinute
end

private def self.compute_second_and_tenth_microsecond
Expand Down

0 comments on commit a056f36

Please sign in to comment.