on 577fc17 help sign in
elk/libraries/Date.elm
76 lines 2.2 kB history raw
2module Date where
4{-| Library for working with dates. Email the mailing list if you encounter
5issues with internationalization or locale formatting.
7# Conversions
8@docs read, toTime, fromTime
10# Extractions
11@docs year, month, Month, day, dayOfWeek, Day, hour, minute, second
13-}
15import Native.Date
16import Time (Time)
17import Maybe (Maybe)
19data Date = Date
21{-| Represents the days of the week. -}
22data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
24{-| Represents the month of the year. -}
25data Month = Jan | Feb | Mar | Apr
26 | May | Jun | Jul | Aug
27 | Sep | Oct | Nov | Dec
29{-| Attempt to read a date from a string. -}
30read : String -> Maybe Date
31read = Native.Date.read
33{-| Convert a date into a time since midnight (UTC) of 1 January 1990 (i.e.
34[UNIX time](http://en.wikipedia.org/wiki/Unix_time)). Given the date 23 June
351990 at 11:45AM this returns the corresponding time. -}
36toTime : Date -> Time
37toTime = Native.Date.toTime
39{-| Take a UNIX time and convert it to a `Date` -}
40fromTime : Time -> Date
41fromTime = Native.Date.fromTime
43{-| Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
44this returns the integer `1990`. -}
45year : Date -> Int
46year = Native.Date.year
48{-| Extract the month of a given date. Given the date 23 June 1990 at 11:45AM
49this returns the Month `Jun` as defined below. -}
50month : Date -> Month
51month = Native.Date.month
53{-| Extract the day of a given date. Given the date 23 June 1990 at 11:45AM
54this returns the integer `23`. -}
55day : Date -> Int
56day = Native.Date.day
58{-| Extract the day of the week for a given date. Given the date 23 June
591990 at 11:45AM this returns the Day `Thu` as defined below. -}
60dayOfWeek : Date -> Day
61dayOfWeek = Native.Date.dayOfWeek
63{-| Extract the hour of a given date. Given the date 23 June 1990 at 11:45AM
64this returns the integer `11`. -}
65hour : Date -> Int
66hour = Native.Date.hour
68{-| Extract the minute of a given date. Given the date 23 June 1990 at 11:45AM
69this returns the integer `45`. -}
70minute : Date -> Int
71minute = Native.Date.minute
73{-| Extract the second of a given date. Given the date 23 June 1990 at 11:45AM
74this returns the integer `0`. -}
75second : Date -> Int
76second = Native.Date.second