Skip to content

Commit

Permalink
fix(dateFromFields): day light saving compensation
Browse files Browse the repository at this point in the history
It now compensates for the difference between day light saving offset at epoch date verse day light saving offset now.
test(CreateTests): Now filters out tests not in current time zone so no errors appear any more for other time zones. This does mean that to get clean bill of health for tests they need to be run in 3 time zones at least.  Sydney, Brisbane, NewFoundland
  • Loading branch information
rluiten committed Jul 10, 2016
1 parent 0f1e5cf commit 500a591
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 247 deletions.
2 changes: 1 addition & 1 deletion elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.2.0",
"version": "7.2.1",
"summary": "Date Extra library add/subtract/diff/format etc dates.",
"repository": "https://github.com/rluiten/elm-date-extra.git",
"license": "BSD3",
Expand Down
29 changes: 23 additions & 6 deletions src/Date/Extra/Create.elm
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ epochDate = Date.fromTime 0


{- The TimezoneOffset of epochDate in current vm.
Return is negated to match sign of getTimeZoneOffsset
Y/M/D comes out 1969-12-31. The date time zone offset is negative hours minutes
Y/M/D comes out 1970-01-01. The date time offset is positive hours minutes
-}
epochTimezoneOffset =
let
inMinutes = (Date.hour epochDate * 60) + Date.minute epochDate
in
if ((Date.year epochDate) == 1969) then
inMinutes - (24*60)
-(inMinutes - (24*60))
else
inMinutes
-inMinutes


{-| Create a date in current time zone from given fields.
Expand All @@ -73,12 +75,27 @@ dateFromFields year month day hour minute second millisecond =
(Internal.ticksFromFields year month day hour minute second millisecond)


{-
This now compensates for current timezone offset compared to epoch offset.
In relation to #17.
-}
adjustedTicksToDate : Int -> Date
adjustedTicksToDate ticks =
Period.add
Period.Millisecond
(ticks - (epochTimezoneOffset * Core.ticksAMinute))
epochDate
let
date =
Period.add
Period.Millisecond
(ticks + (epochTimezoneOffset * Core.ticksAMinute))
epochDate
dateOffset = getTimezoneOffset date
in
if dateOffset == epochTimezoneOffset then
date
else
Period.add
Period.Minute
(dateOffset - epochTimezoneOffset)
date


{-| Create a time in current time zone from given fields, for
Expand Down
Loading

0 comments on commit 500a591

Please sign in to comment.