Add Date.fromTime function, based on PR #357

This commit is contained in:
Evan Czaplicki 2014-01-28 23:56:20 +01:00
parent f636b7576f
commit f5c612f13c
2 changed files with 6 additions and 1 deletions

View file

@ -5,7 +5,7 @@ module Date where
issues with internationalization or locale formatting.
# Conversions
@docs read, toTime
@docs read, toTime, fromTime
# Extractions
@docs year, month, Month, day, dayOfWeek, Day, hour, minute, second
@ -36,6 +36,10 @@ read = Native.Date.read
toTime : Date -> Time
toTime = Native.Date.toTime
{-| Take a UNIX time and convert it to a `Date` -}
fromTime : Time -> Date
fromTime = Native.Date.fromTime
{-| Extract the year of a given date. Given the date 23 June 1990 at 11:45AM
this returns the integer `1990`. -}
year : Date -> Int

View file

@ -27,6 +27,7 @@ Elm.Native.Date.make = function(elm) {
minute : function(d) { return d.getMinutes(); },
second : function(d) { return d.getSeconds(); },
toTime : function(d) { return d.getTime(); },
fromTime: function(t) { return new window.Date(t); },
dayOfWeek : function(d) { return { ctor:dayTable[d.getDay()] }; }
};