arowM/tepa-zoned-time/1.0.1

ZonedTime

A module to handle zoned time.

Core

fromPosix : Zone -> Posix -> ZonedTime
{ year : Int
, month : Month
, day : Int
}
-> Maybe ZonedTime

Construct ZonedTime from proleptic Gregorian calendar day in UTC. Invalid values will return Nothing.

import Tepa.Time as Time


sample : Maybe ZonedTime
sample =
    fromGregorianUtc
        { year = 2000
        , month = Time.Jun
        , day = 10
        }
        |> Maybe.map (addHours 22)
        |> Maybe.map (addMinutes 33)
        |> Maybe.map (addSeconds 44)
        |> Maybe.map (addMillis 55)


Maybe.map toZone sample
--> Just Time.utc


Maybe.map getYear sample
--> Just 2000


Maybe.map getMonth sample
--> Just Time.Jun


Maybe.map getDay sample
--> Just 10


Maybe.map getHour sample
--> Just 22


Maybe.map getMinute sample
--> Just 33


Maybe.map getSecond sample
--> Just 44


Maybe.map getMillis sample
--> Just 55


fromGregorianUtc
    { year = 1999
    , month = Time.Feb
    , day = 29
    }
--> Nothing
now : Promise x ZonedTime
toPosix : ZonedTime -> Posix
toZone : ZonedTime -> Zone

Operators

Overwrite time zone. Make sure it will not change internal POSIX time value.

import TimeZone
import Tepa.Time as Time


-- 1970-01-04T13:54:12.123Z
original : ZonedTime
original = fromPosix Time.utc (Time.millisToPosix 309252123)


fooZone : Time.Zone
fooZone = TimeZone.asia__tokyo ()


sample1 : ZonedTime
sample1 =
    original
        |> overwriteZone fooZone


sample2 : ZonedTime
sample2 =
    original
        |> addHours -9
        |> overwriteZone fooZone


toZone sample1
--> fooZone


toZone sample2
--> fooZone


getHour sample1
--> 22


getHour sample2
--> 13
mapPosix : (Posix -> Posix) -> ZonedTime -> ZonedTime

Modify internal POSIX time value.

Set time to midnight of the day in the time zone. Shorthand for resetMillis >> resetSecond >> resetMinute >> resetHour.

import Tepa.Time as Time


-- 1970-01-04T13:54:12.123Z
original : ZonedTime
original = fromPosix Time.utc (Time.millisToPosix 309252123)


midnight : ZonedTime
midnight =
    setToMidnight original


getYear original
--> 1970


getYear midnight
--> 1970


getMonth original
--> Time.Jan


getMonth midnight
--> Time.Jan


getDay original
--> 4


getDay midnight
--> 4


getHour midnight
--> 0


getMinute midnight
--> 0


getSecond midnight
--> 0


getMillis midnight
--> 0

Getters

getMonth : ZonedTime -> Month
getDay : ZonedTime -> Int
getWeekday : ZonedTime -> Weekday

Reset functions

Reset the hour part of ZonedTime to zero.

Shorthand for \time -> addHours (negate <| getHour time) time.

Reset the minute part of ZonedTime to zero.

Shorthand for \time -> addMinutes (negate <| getMinute time) time.

Reset the second part of ZonedTime to zero.

Shorthand for \time -> addSeconds (negate <| getSecond time) time.

Reset the millis part of ZonedTime to zero.

Shorthand for \time -> addMillis (negate <| getMillis time) time.

Utilities

isLeapYear : Int -> Bool

Check if the year of given number is a leap year.

daysInYear : Int -> Int

Return the number of days in the year specified as an argument.

daysInMonth : Int -> Month -> Int

Return the number of days in the month specified by the given year and month arguments.