Module

Data.JSDate

A module providing a type and operations for the native JavaScript Date object.

The JSDate type and associated functions are provided for interop purposes with JavaScript, but for working with dates in PureScript it is recommended that DateTime representation is used instead - DateTime offers greater type safety, a more PureScript-friendly interface, and has a Generic instance.

#JSDate

data JSDate

The type of JavaScript Date objects.

Instances

#readDate

readDate :: Foreign -> F JSDate

Attempts to read a Foreign value as a JSDate.

#isValid

isValid :: JSDate -> Boolean

Checks whether a date value is valid. When a date is invalid, the majority of the functions return NaN, "Invalid Date", or throw an exception.

#fromDateTime

fromDateTime :: DateTime -> JSDate

Converts a DateTime value into a native JavaScript date object. The resulting date value is guaranteed to be valid.

#toDateTime

toDateTime :: JSDate -> Maybe DateTime

Attempts to construct a DateTime value for a JSDate. Nothing is returned only when the date value is an invalid date.

#toDate

toDate :: JSDate -> Maybe Date

Attempts to construct a Date value for a JSDate, ignoring any time component of the JSDate. Nothing is returned only when the date value is an invalid date.

#fromInstant

fromInstant :: Instant -> JSDate

Creates a JSDate from an Instant value.

#toInstant

toInstant :: JSDate -> Maybe Instant

Attempts to construct an Instant for a JSDate. Nothing is returned only when the date value is an invalid date.

#jsdate

jsdate :: { day :: Number, hour :: Number, millisecond :: Number, minute :: Number, month :: Number, second :: Number, year :: Number } -> JSDate

Constructs a new JSDate from UTC component values. If any of the values are NaN the resulting date will be invalid.

#jsdateLocal

jsdateLocal :: { day :: Number, hour :: Number, millisecond :: Number, minute :: Number, month :: Number, second :: Number, year :: Number } -> Effect JSDate

Constructs a new JSDate from component values using the current machine's locale. If any of the values are NaN the resulting date will be invalid.

#now

now :: Effect JSDate

Gets a JSDate value for the date and time according to the current machine's clock.

Unless a JSDate is required specifically, consider using the functions in Effect.Now instead.

#parse

parse :: String -> Effect JSDate

Attempts to parse a date from a string. The behavior of this function is implementation specific until ES5, so may not always have the same behavior for a given string. For this reason, it is strongly encouraged that you avoid this function if at all possible.

If you must use it, the RFC2822 and ISO8601 date string formats should parse consistently.

This function is effectful because if no time zone is specified in the string the current locale's time zone will be used instead.

#getTime

getTime :: JSDate -> Number

Returns the date as a number of milliseconds since 1970-01-01 00:00:00 UTC.

#getUTCDate

getUTCDate :: JSDate -> Number

Returns the day of the month for a date, according to UTC.

#getUTCDay

getUTCDay :: JSDate -> Number

Returns the day of the week for a date, according to UTC.

#getUTCFullYear

getUTCFullYear :: JSDate -> Number

Returns the year for a date, according to UTC.

#getUTCHours

getUTCHours :: JSDate -> Number

Returns the hours for a date, according to UTC.

#getUTCMilliseconds

getUTCMilliseconds :: JSDate -> Number

Returns the milliseconds for a date, according to UTC.

#getUTCMinutes

getUTCMinutes :: JSDate -> Number

Returns the minutes for a date, according to UTC.

#getUTCMonth

getUTCMonth :: JSDate -> Number

Returns the month for a date, according to UTC.

#getUTCSeconds

getUTCSeconds :: JSDate -> Number

Returns the seconds for a date, according to UTC.

#getDate

getDate :: JSDate -> Effect Number

Returns the day of the month for a date, according to the current machine's date/time locale.

#getDay

getDay :: JSDate -> Effect Number

Returns the day of the week for a date, according to the current machine's date/time locale.

#getFullYear

getFullYear :: JSDate -> Effect Number

Returns the year for a date, according to the current machine's date/time locale.

#getHours

getHours :: JSDate -> Effect Number

Returns the hour for a date, according to the current machine's date/time locale.

#getMilliseconds

getMilliseconds :: JSDate -> Effect Number

Returns the milliseconds for a date, according to the current machine's date/time locale.

#getMinutes

getMinutes :: JSDate -> Effect Number

Returns the minutes for a date, according to the current machine's date/time locale.

#getMonth

getMonth :: JSDate -> Effect Number

Returns the month for a date, according to the current machine's date/time locale.

#getSeconds

getSeconds :: JSDate -> Effect Number

Returns the seconds for a date, according to the current machine's date/time locale.

#getTimezoneOffset

getTimezoneOffset :: JSDate -> Effect Number

Returns the time-zone offset for a date, according to the current machine's date/time locale.

#toDateString

toDateString :: JSDate -> String

Returns the date portion of a date value as a human-readable string.

#toISOString

toISOString :: JSDate -> Effect String

Converts a date value to an ISO 8601 Extended format date string.

#toString

toString :: JSDate -> String

Returns a string representing for a date value.

#toTimeString

toTimeString :: JSDate -> String

Returns the time portion of a date value as a human-readable string.

#toUTCString

toUTCString :: JSDate -> String

Returns the date as a string using the UTC timezone.

#fromTime

fromTime :: Number -> JSDate

Returns the date at a number of milliseconds since 1970-01-01 00:00:00 UTC.

Modules