Skip to content

Commit

Permalink
Merge pull request #17 from pendletong/fix_offset
Browse files Browse the repository at this point in the history
fix for offset check when month or year changes
  • Loading branch information
massivefermion authored Apr 1, 2024
2 parents f8b6460 + bf0db8f commit b145096
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/birl_ffi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ now() -> os:system_time(microsecond).

local_offset() ->
Timestamp = erlang:timestamp(),
{{_, _, LD}, {LH, LM, _}} = calendar:now_to_local_time(Timestamp),
{{_, _, UD}, {UH, UM, _}} = calendar:now_to_universal_time(Timestamp),
{{LY, LN, LD}, {LH, LM, _}} = calendar:now_to_local_time(Timestamp),
{{UY, UN, UD}, {UH, UM, _}} = calendar:now_to_universal_time(Timestamp),
if
LD == UD -> (LH - UH) * 60 + LM - UM;
LD > UD -> (23 - UH) * 60 + (60 - UM) + LH * 60 + LM;
LD > UD orelse LN > UN orelse LY > UY -> (23 - UH) * 60 + (60 - UM) + LH * 60 + LM;
LD < UD -> -((23 - LH) * 60 + (60 - LM) + UH * 60 + UM)
end.

Expand Down

0 comments on commit b145096

Please sign in to comment.