A module to handle zoned time.
Construct ZonedTime from proleptic Gregorian calendar day in UTC.
Invalid values will return Nothing.
import 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
}
--> NothingOverwrite time zone. Make sure it will not change internal POSIX time value.
import Time
-- 1970-01-04T13:54:12.123Z
original : ZonedTime
original = fromPosix Time.utc (Time.millisToPosix 309252123)
fooZone : Time.Zone
fooZone = Time.customZone (9 * 60) []
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
--> 13Set time to midnight of the day in the time zone.
import 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
--> 0Check if the year of given number is a leap year.
Return the number of days in the year specified as an argument.
Return the number of days in the month specified by the given year and month arguments.