AdrianRibao / elm-derberos-date / Derberos.Date.Core

Core functions for working with dates


type alias DateRecord =
{ year : Basics.Int
, month : Basics.Int
, day : Basics.Int
, hour : Basics.Int
, minute : Basics.Int
, second : Basics.Int
, millis : Basics.Int
, zone : Time.Zone 
}

Store the date in a record.

newDateRecord : Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> Time.Zone -> DateRecord

Generate a new DateRecord

newDateRecord 2018 2 13 19 45 0 0 == {
    year = 2018
    , month = 2
    , day = 13
    , hour = 19
    , minute = 45
    , second = 0
    , millis = 0
    }

civilToPosix : DateRecord -> Time.Posix

Given a datetime, get the posix time.

posixToCivil : Time.Posix -> DateRecord

Given a Posix time, get the human datetime.


type alias Config =
{ getMonthName : Time.Month -> String
, getWeekName : Time.Weekday -> String
, getCommonFormatDate : String -> Time.Zone -> Time.Posix -> String
, getCommonFormatTime : Time.Zone -> Time.Posix -> String
, getCommonFormatDateTime : String -> Time.Zone -> Time.Posix -> String 
}

Store the configuration for getting i18n and l10n formats.

Timezones

getTzOffset : Time.Zone -> Time.Posix -> Basics.Int

Gets the difference in minutes given the current Time Zone and the utc time.

adjustMilliseconds : Time.Zone -> Time.Posix -> Time.Posix

Adjust the milliseconds of the posix time.

The time has the milliseconds as if it was using UTC but it actually has a tz to be applied. So if we had 2018/10/28T01:30:00 UTC we want to convert it to 2018/10/28T01:30:00 zone so we have to substract the offset.

addTimezoneMilliseconds : Time.Zone -> Time.Posix -> Time.Posix

Given a Zone and a Posix time, add the timezone offset to get the corrected date.