on master help sign in
Add Date.fromTime function, based on PR #357
commitf5c612f13c5452cce024949ecfbd737aefc3f4bf authorEvan Czaplicki <info@elm-lang.org> dateTue 28 Jan 2014, 23:56 (13 years ago) parentf636b75
2 files changed+6−1
libraries/Date.elm+5−1 libraries/Native/Date.js+1
libraries/Date.elm+5−1
@@ -5,7 +5,7 @@ module Date where
55issues with internationalization or locale formatting.
66
77# Conversions
8−@docs read, toTime
8+@docs read, toTime, fromTime
99
1010# Extractions
1111@docs year, month, Month, day, dayOfWeek, Day, hour, minute, second
@@ -36,6 +36,10 @@ read = Native.Date.read
3636toTime : Date -> Time
3737toTime = Native.Date.toTime
3838
39+{-| Take a UNIX time and convert it to a `Date` -}
40+fromTime : Time -> Date
41+fromTime = Native.Date.fromTime
42+
3943{-| Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
4044this returns the integer `1990`. -}
4145year : Date -> Int
libraries/Native/Date.js+1
@@ -27,6 +27,7 @@ Elm.Native.Date.make = function(elm) {
2727 minute : function(d) { return d.getMinutes(); },
2828 second : function(d) { return d.getSeconds(); },
2929 toTime : function(d) { return d.getTime(); },
30+ fromTime: function(t) { return new window.Date(t); },
3031 dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; }
3132 };
3233