package server-reason-react

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Js.DateSource

JavaScript Date implementation following ECMA-262 §21.4

This is a spec-compliant implementation using only OCaml stdlib + Unix. Internal representation: float (milliseconds since Unix epoch, or NaN for invalid dates).

Sourcetype t = float

The Date type - represents milliseconds since Unix epoch, or NaN for invalid dates

Constructors

Sourceval make : unit -> t

Returns a date representing the current time

Sourceval fromFloat : float -> t

Create a Date from epoch milliseconds

Sourceval of_epoch_ms : float -> t

Alias for fromFloat

Sourceval fromString : string -> t

Create a Date by parsing a string

Sourceval makeWithYM : year:float -> month:float -> t

Create a Date from year and month (local time). Note: Years 0-99 are treated as 1900-1999

Sourceval makeWithYMD : year:float -> month:float -> date:float -> t

Create a Date from year, month, date (local time)

Sourceval makeWithYMDH : year:float -> month:float -> date:float -> hours:float -> t

Create a Date from year, month, date, hours (local time)

Sourceval makeWithYMDHM : year:float -> month:float -> date:float -> hours:float -> minutes:float -> t

Create a Date from year, month, date, hours, minutes (local time)

Sourceval makeWithYMDHMS : year:float -> month:float -> date:float -> hours:float -> minutes:float -> seconds:float -> t

Create a Date from all components (local time)

Date.UTC constructors

Sourceval utc : year:float -> month:float -> ?day:float -> ?hours:float -> ?minutes:float -> ?seconds:float -> ?ms:float -> unit -> float

Date.UTC(year, month, date[, hours[, minutes[, seconds[, ms]]]]) Returns epoch milliseconds for the given UTC date components. Note: Years 0-99 are treated as 1900-1999

Sourceval utcWithYM : year:float -> month:float -> float

Date.UTC with year and month only

Sourceval utcWithYMD : year:float -> month:float -> date:float -> float

Date.UTC with year, month, date

Sourceval utcWithYMDH : year:float -> month:float -> date:float -> hours:float -> float

Date.UTC with year, month, date, hours

Sourceval utcWithYMDHM : year:float -> month:float -> date:float -> hours:float -> minutes:float -> float

Date.UTC with year, month, date, hours, minutes

Sourceval utcWithYMDHMS : year:float -> month:float -> date:float -> hours:float -> minutes:float -> seconds:float -> float

Date.UTC with all components

Date.now and Date.parse

Sourceval now : unit -> float

Date.now() - returns current time as epoch milliseconds

Sourceval parse : string -> float

Date.parse(string) - parses a date string, returns NaN on failure. Supports ISO 8601 and legacy formats.

Sourceval parseAsFloat : string -> float

Alias for parse

UTC Getters

Sourceval valueOf : t -> float

Returns the primitive value (epoch ms), equivalent to getTime

Sourceval getTime : t -> float

Returns the epoch milliseconds

Sourceval getUTCDate : t -> float

Returns the day of the month (1-31) in UTC

Sourceval getUTCDay : t -> float

Returns the day of the week (0=Sunday, 6=Saturday) in UTC

Sourceval getUTCFullYear : t -> float

Returns the year in UTC

Sourceval getUTCHours : t -> float

Returns the hours (0-23) in UTC

Sourceval getUTCMilliseconds : t -> float

Returns the milliseconds (0-999) in UTC

Sourceval getUTCMinutes : t -> float

Returns the minutes (0-59) in UTC

Sourceval getUTCMonth : t -> float

Returns the month (0-11) in UTC

Sourceval getUTCSeconds : t -> float

Returns the seconds (0-59) in UTC

Local Time Getters

Sourceval getDate : t -> float

Returns the day of the month (1-31) in local time

Sourceval getDay : t -> float

Returns the day of the week (0=Sunday, 6=Saturday) in local time

Sourceval getFullYear : t -> float

Returns the year in local time

Sourceval getHours : t -> float

Returns the hours (0-23) in local time

Sourceval getMilliseconds : t -> float

Returns the milliseconds (0-999) in local time

Sourceval getMinutes : t -> float

Returns the minutes (0-59) in local time

Sourceval getMonth : t -> float

Returns the month (0-11) in local time

Sourceval getSeconds : t -> float

Returns the seconds (0-59) in local time

Sourceval getTimezoneOffset : t -> float

Returns the timezone offset in minutes (positive = west of UTC)

UTC Setters

All setters return the new timestamp (milliseconds).

Sourceval setUTCDate : float -> t -> float
Sourceval setUTCFullYear : float -> t -> float
Sourceval setUTCFullYearM : year:float -> month:float -> t -> float
Sourceval setUTCFullYearMD : year:float -> month:float -> date:float -> t -> float
Sourceval setUTCHours : float -> t -> float
Sourceval setUTCHoursM : hours:float -> minutes:float -> t -> float
Sourceval setUTCHoursMS : hours:float -> minutes:float -> seconds:float -> t -> float
Sourceval setUTCHoursMSMs : hours:float -> minutes:float -> seconds:float -> milliseconds:float -> t -> float
Sourceval setUTCMilliseconds : float -> t -> float
Sourceval setUTCMinutes : float -> t -> float
Sourceval setUTCMinutesS : minutes:float -> seconds:float -> t -> float
Sourceval setUTCMinutesSMs : minutes:float -> seconds:float -> milliseconds:float -> t -> float
Sourceval setUTCMonth : float -> t -> float
Sourceval setUTCMonthD : month:float -> date:float -> t -> float
Sourceval setUTCSeconds : float -> t -> float
Sourceval setUTCSecondsMs : seconds:float -> milliseconds:float -> t -> float
Sourceval setUTCTime : float -> t -> float

Local Time Setters

All setters return the new timestamp (milliseconds).

Sourceval setDate : float -> t -> float
Sourceval setFullYear : float -> t -> float
Sourceval setFullYearM : year:float -> month:float -> t -> float
Sourceval setFullYearMD : year:float -> month:float -> date:float -> t -> float
Sourceval setHours : float -> t -> float
Sourceval setHoursM : hours:float -> minutes:float -> t -> float
Sourceval setHoursMS : hours:float -> minutes:float -> seconds:float -> t -> float
Sourceval setHoursMSMs : hours:float -> minutes:float -> seconds:float -> milliseconds:float -> t -> float
Sourceval setMilliseconds : float -> t -> float
Sourceval setMinutes : float -> t -> float
Sourceval setMinutesS : minutes:float -> seconds:float -> t -> float
Sourceval setMinutesSMs : minutes:float -> seconds:float -> milliseconds:float -> t -> float
Sourceval setMonth : float -> t -> float
Sourceval setMonthD : month:float -> date:float -> t -> float
Sourceval setSeconds : float -> t -> float
Sourceval setSecondsMs : seconds:float -> milliseconds:float -> t -> float
Sourceval setTime : float -> t -> float

String Conversion

Sourceval toDateString : t -> string

Returns a human-readable date string (local time)

Sourceval toISOString : t -> string

Returns an ISO 8601 formatted string: "YYYY-MM-DDTHH:mm:ss.sssZ" Raises Invalid_argument for invalid dates

Sourceval toJSON : t -> string option

Returns ISO string wrapped in option, None for invalid dates

Sourceval toJSONUnsafe : t -> string

Same as toISOString - throws for invalid dates

Sourceval toLocaleDateString : t -> string

Returns locale-formatted date string (simplified implementation)

Sourceval toLocaleString : t -> string

Returns locale-formatted string (simplified implementation)

Sourceval toLocaleTimeString : t -> string

Returns locale-formatted time string (simplified implementation)

Sourceval toString : t -> string

Returns full string representation in local time

Sourceval toTimeString : t -> string

Returns time string in local time

Sourceval toUTCString : t -> string

Returns string in UTC: "Tue, 02 Dec 2025 09:30:00 GMT"