From f5c612f13c5452cce024949ecfbd737aefc3f4bf Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Tue, 28 Jan 2014 23:56:20 +0100 Subject: [PATCH] Add Date.fromTime function, based on PR #357 --- libraries/Date.elm | 6 +++++- libraries/Native/Date.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/Date.elm b/libraries/Date.elm index 573ab53..643cf0b 100644 --- a/libraries/Date.elm +++ b/libraries/Date.elm @@ -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 diff --git a/libraries/Native/Date.js b/libraries/Native/Date.js index 1b34231..2858830 100644 --- a/libraries/Native/Date.js +++ b/libraries/Native/Date.js @@ -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()] }; } };