miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

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.new
  iso  <- D.toISOString now     -- e.g. "2026-06-23T12:00:00.000Z"
  year <- D.getFullYear now     -- e.g. 2026
  ms   <- D.valueOf now         -- milliseconds since Unix epoch
  pure ()

API groups

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

Type

data Date Source #

Instances

Instances details
Eq Date Source # 
Instance details

Defined in Miso.Date

Methods

(==) :: Date -> Date -> Bool #

(/=) :: Date -> Date -> Bool #

FromJSVal Date Source # 
Instance details

Defined in Miso.Date

ToJSVal Date Source # 
Instance details

Defined in Miso.Date

Methods

toJSVal :: Date -> IO JSVal Source #

ToObject Date Source # 
Instance details

Defined in Miso.Date

Methods

toObject :: Date -> IO Object Source #

Construction

new :: IO Date Source #

Constructs a new JS Date in IO.

Conversion

Getters

getDate :: Date -> IO Int Source #

Returns the day of the month.

getDay :: Date -> IO Int Source #

Returns the day of the week.

getFullYear :: Date -> IO Int Source #

Returns the full year.

getHours :: Date -> IO Int Source #

Returns the hour.

getMilliseconds :: Date -> IO Int Source #

Returns the milliseconds.

getMinutes :: Date -> IO Int Source #

Returns the minutes.

getMonth :: Date -> IO Int Source #

Returns the month (0-11).

getSeconds :: Date -> IO Int Source #

Returns the seconds.

getTime :: Date -> IO Double Source #

Returns milliseconds since epoch.

getTimezoneOffset :: Date -> IO Int Source #

Returns the time zone offset in minutes.

getUTCDate :: Date -> IO Int Source #

Returns the UTC day of the month.

getUTCDay :: Date -> IO Int Source #

Returns the UTC day of the week.

getUTCFullYear :: Date -> IO Int Source #

Returns the UTC full year.

getUTCHours :: Date -> IO Int Source #

Returns the UTC hour.

getUTCMilliseconds :: Date -> IO Int Source #

Returns the UTC milliseconds.

getUTCMinutes :: Date -> IO Int Source #

Returns the UTC minutes.

getUTCMonth :: Date -> IO Int Source #

Returns the UTC month (0-11).

getUTCSeconds :: Date -> IO Int Source #

Returns the UTC seconds.

Setters

setDate Source #

Arguments

:: Int

Day of the month (1–31)

-> Date

Date object to modify

-> IO Double 

Sets the day of the month.

setFullYear Source #

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.

setHours Source #

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.

setMilliseconds Source #

Arguments

:: Int

Milliseconds (0–999)

-> Date

Date object to modify

-> IO Double 

Sets the milliseconds.

setMinutes Source #

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.

setMonth Source #

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.

setSeconds Source #

Arguments

:: Int

Seconds (0–59)

-> Maybe Int

Optional milliseconds (0–999)

-> Date

Date object to modify

-> IO Double 

Sets the seconds, with optional milliseconds.

setTime Source #

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.

setUTCDate Source #

Arguments

:: Int

Day of the month in UTC (1–31)

-> Date

Date object to modify

-> IO Double 

Sets the UTC day of the month.

setUTCFullYear Source #

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.

setUTCHours Source #

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.

setUTCMilliseconds Source #

Arguments

:: Int

Milliseconds in UTC (0–999)

-> Date

Date object to modify

-> IO Double 

Sets the UTC milliseconds.

setUTCMinutes Source #

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.

setUTCMonth Source #

Arguments

:: Int

Month in UTC (0-indexed: 0 = January)

-> Maybe Int

Optional day in UTC (1–31)

-> Date

Date object to modify

-> IO Double 

Sets the UTC month, with optional day of the month.

setUTCSeconds Source #

Arguments

:: Int

Seconds in UTC (0–59)

-> Maybe Int

Optional milliseconds (0–999)

-> Date

Date object to modify

-> IO Double 

Sets the UTC seconds, with optional milliseconds.