| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Date
Description
Overview
Miso.Date is a Haskell wrapper around the JavaScript
Date
object. A Date value lives in JavaScript memory and represents a single
point in time. All operations run in IO and call through to the
underlying JS object.
Import qualified to avoid clashing with Prelude:
import qualified Miso.Date as D
Quick start
import qualified Miso.Date as D example :: IO () example = do now <- D.newiso <- D.toISOStringnow -- e.g. "2026-06-23T12:00:00.000Z" year <- D.getFullYearnow -- e.g. 2026 ms <- D.valueOfnow -- milliseconds since Unix epoch pure ()
API groups
- Construction:
new - Conversion (strings):
toDateString,toISOString,toJSON,toLocaleDateString,toLocaleString,toLocaleTimeString,toString,toTimeString,toUTCString - Conversion (numeric):
valueOf(ms since epoch) - Local getters:
getDate,getDay,getFullYear,getHours,getMilliseconds,getMinutes,getMonth,getSeconds,getTime,getTimezoneOffset - UTC getters:
getUTCDate,getUTCDay,getUTCFullYear,getUTCHours,getUTCMilliseconds,getUTCMinutes,getUTCMonth,getUTCSeconds - Local setters:
setDate,setFullYear,setHours,setMilliseconds,setMinutes,setMonth,setSeconds,setTime - UTC setters:
setUTCDate,setUTCFullYear,setUTCHours,setUTCMilliseconds,setUTCMinutes,setUTCMonth,setUTCSeconds
Note: JavaScript months are 0-indexed (January = 0, December = 11).
All getter and setter functions in this module follow that convention.
Setter functions return the new timestamp as milliseconds since the Unix
epoch (a Double), mirroring the JavaScript return value.
See also
Synopsis
- data Date
- new :: IO Date
- toDateString :: Date -> IO MisoString
- toISOString :: Date -> IO MisoString
- toJSON :: Date -> IO MisoString
- toLocaleDateString :: Date -> IO MisoString
- toLocaleString :: Date -> IO MisoString
- toLocaleTimeString :: Date -> IO MisoString
- toString :: Date -> IO MisoString
- toTimeString :: Date -> IO MisoString
- toUTCString :: Date -> IO MisoString
- valueOf :: Date -> IO Double
- getDate :: Date -> IO Int
- getDay :: Date -> IO Int
- getFullYear :: Date -> IO Int
- getHours :: Date -> IO Int
- getMilliseconds :: Date -> IO Int
- getMinutes :: Date -> IO Int
- getMonth :: Date -> IO Int
- getSeconds :: Date -> IO Int
- getTime :: Date -> IO Double
- getTimezoneOffset :: Date -> IO Int
- getUTCDate :: Date -> IO Int
- getUTCDay :: Date -> IO Int
- getUTCFullYear :: Date -> IO Int
- getUTCHours :: Date -> IO Int
- getUTCMilliseconds :: Date -> IO Int
- getUTCMinutes :: Date -> IO Int
- getUTCMonth :: Date -> IO Int
- getUTCSeconds :: Date -> IO Int
- setDate :: Int -> Date -> IO Double
- setFullYear :: Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setHours :: Int -> Maybe Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setMilliseconds :: Int -> Date -> IO Double
- setMinutes :: Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setMonth :: Int -> Maybe Int -> Date -> IO Double
- setSeconds :: Int -> Maybe Int -> Date -> IO Double
- setTime :: Double -> Date -> IO Double
- setUTCDate :: Int -> Date -> IO Double
- setUTCFullYear :: Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setUTCHours :: Int -> Maybe Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setUTCMilliseconds :: Int -> Date -> IO Double
- setUTCMinutes :: Int -> Maybe Int -> Maybe Int -> Date -> IO Double
- setUTCMonth :: Int -> Maybe Int -> Date -> IO Double
- setUTCSeconds :: Int -> Maybe Int -> Date -> IO Double
Type
Construction
Conversion
toDateString :: Date -> IO MisoString Source #
Returns a human-readable date string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString
toISOString :: Date -> IO MisoString Source #
Returns an ISO 8601 string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
toJSON :: Date -> IO MisoString Source #
Returns the JSON representation of the date.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON
toLocaleDateString :: Date -> IO MisoString Source #
Returns a locale-sensitive date string.
toLocaleString :: Date -> IO MisoString Source #
Returns a locale-sensitive date and time string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
toLocaleTimeString :: Date -> IO MisoString Source #
Returns a locale-sensitive time string.
toString :: Date -> IO MisoString Source #
Returns the full date string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
toTimeString :: Date -> IO MisoString Source #
toUTCString :: Date -> IO MisoString Source #
valueOf :: Date -> IO Double Source #
Returns the primitive value (milliseconds since epoch).
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf
Getters
Setters
Sets the day of the month.
Arguments
| :: Int | Full year (e.g. 2026) |
| -> Maybe Int | Optional month (0-indexed: 0 = January) |
| -> Maybe Int | Optional day of the month (1–31) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the full year, with optional month and day.
Arguments
| :: Int | Hour (0–23) |
| -> Maybe Int | Optional minutes (0–59) |
| -> Maybe Int | Optional seconds (0–59) |
| -> Maybe Int | Optional milliseconds (0–999) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the hour, with optional minutes, seconds, and milliseconds.
Sets the milliseconds.
Arguments
| :: Int | Minutes (0–59) |
| -> Maybe Int | Optional seconds (0–59) |
| -> Maybe Int | Optional milliseconds (0–999) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the minutes, with optional seconds and milliseconds.
Arguments
| :: Int | Month (0-indexed: 0 = January, 11 = December) |
| -> Maybe Int | Optional day of the month (1–31) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the month, with optional day of the month.
Arguments
| :: Int | Seconds (0–59) |
| -> Maybe Int | Optional milliseconds (0–999) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the seconds, with optional milliseconds.
Arguments
| :: Double | Milliseconds since the Unix epoch (1 January 1970 00:00:00 UTC) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the time in milliseconds since epoch.
Sets the UTC day of the month.
Arguments
| :: Int | Full year in UTC (e.g. 2026) |
| -> Maybe Int | Optional month in UTC (0-indexed) |
| -> Maybe Int | Optional day in UTC (1–31) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the UTC full year, with optional month and day.
Arguments
| :: Int | Hour in UTC (0–23) |
| -> Maybe Int | Optional minutes (0–59) |
| -> Maybe Int | Optional seconds (0–59) |
| -> Maybe Int | Optional milliseconds (0–999) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the UTC hour, with optional minutes, seconds, and milliseconds.
Sets the UTC milliseconds.
Arguments
| :: Int | Minutes in UTC (0–59) |
| -> Maybe Int | Optional seconds (0–59) |
| -> Maybe Int | Optional milliseconds (0–999) |
| -> Date | Date object to modify |
| -> IO Double |
Sets the UTC minutes, with optional seconds and milliseconds.