CivilDateTime
(and its siblings) represents a date and time corresponding to the requirements of ISO-8601.
This means specifically that it uses the proleptic Gregorian calendar whose days are 24 hours long and begin and end at midnight.
new CivilDateTime(year, month, day, hours, minutes, seconds?, milliseconds?, microseconds?, nanoseconds?)
The constructor may only be called as such. It takes between 5 and 7 numeric arguments.
year
the Gregorian yearmonth
the Gregorian monthday
the Gregorian day of the monthhours
hour of the dayminutes
minutes of the hourseconds
seconds of the minutes (default: 0)milliseconds
milliseconds of the seconds (default: 0)microseconds
microseconds of the milliseconds (default: 0)nanoseconds
nanoseconds of the microseconds (default: 0)
fromZonedDateTime
creates a new CivilDateTime
object by calculating its values based of the
ZonedDateTime
passed in.
The .year
property represents the year of the CivilDateTime
.
The .month
property represents the month of the CivilDateTime
.
The .day
property represents the day of the month of the CivilDateTime
.
The .hour
property represents the hour of the CivilDateTime
.
The .minute
property represents the minute of the hour of the CivilDateTime
.
The .second
property represents the second of the minute of the CivilDateTime
.
The .millisecond
property represents the sub-second component of the hour of the CivilDateTime
with millisecond precision. It will have a value between 0 and 999.
The .microsecond
property represents the sub-millisecond component of the hour of the CivilDateTime
with microsecond precision. It will have a value between 0 and 999.
The .nanosecond
property represents the sub-second component of the hour of the CivilDateTime
with nanosecond precision. It will have a value between 0 and 999.
The .dayOfWeek
property represents the day of the week where Monday is 1
and Sunday
is 7
in accordance with ISO-8601.
The .dayOfYear
property represents the ordinal day of the Gregorian year according to ISO-8601.
The .weekOfYear
property represents the ISO week-number. Beware that dates at the begining of a
year may be part of a week from the preceding year, and dates at the end of a year may be part of
a week at the beginning of the next year, as the first week of any year is defined as the week that
contains the first Thursday of the week.
datetime.plus({ years?, months?, days?, hours?, minutes?, seconds?, milliseconds?, microseconds?, nanoseconds? }) : CivilDateTime
Creates a new CivilDateTime
object by adding (subtracting for negative values) values to its members.
The specified values must be numeric if specified.
The algorithm is such that:
- the individual values are added to the existing values.
- the range of
nanoseconds
is ensured to be between 0 and 999 by adjusting themicroseconds
- the range of
microseconds
is ensured to be between 0 and 999 by adjusting themilliseconds
- the range of
milliseconds
is ensured to be between 0 and 999 by adjusting theseconds
- the range of
seconds
is ensured to be between 0 and 59 by adjusting theminutes
- the range of
minutes
is ensured to be between 0 and 59 by adjusting thehours
- the range of
hours
is ensured to be between 0 and 23 by adjustingdays
- the range of
days
is ensured to be between 1 and 29-31 depending on the month by adjustingmonth
- the range of
months
is ensured to be between 1 and 12 by adjusting theyears
.
datetime.with({ years?, months?, days?, hours?, minutes?, seconds?, milliseconds?, microseconds?, nanoseconds? }) : CivilDateTime
Creates a new CivilDateTime
object by overriding specified values to its members.
The specified values must be numeric if specified.
Creates a ZonedDateTime
object from this CivilDateTime
within a specific time-zone. The
zone
must be a string
specifying an IANA-Timezone or an offset string as defined in ZonedDateTime.
The filter
argument can be either a string
in the offset format, a number specifying the seconds offset from UTC, or a function that can be passed to Array.prorotype.find
to decide which possible
result to choose.
Since a given CivilDateTime
can specify multiple ZonedDateTime
s with different offsets (near DST changes), this can be used to be unambiguous in which result is selected.
If no filter
is passed, then the earlier result of potentially multiple is chosen.
If no result can be created, because the sepcified time does not exist in the specified timezone or
the passed filter
does not match a result, then an Error will be thrown.
Equivalent to datetime.toDateTimeString()
Equivalent to datetime.toString()
.toDateTimeString()
creates an ISO-8601 compliant string in the format:
year
-month
-day
Thour
:minute
:second
.nanosecond
.
The year
is 0-padded to a minimum of 4 digits. month
, day
, hours
, minutes
, seconds
are 0-padded to a minimum of 2 digits. nanoseconds
is 0-padded to a minimum of 9 digits.
.toWeekDateTimeString()
creates an ISO-8601 compliant string in the format:
year
-Wweek
-weekday
Thour
:minute
:second
.nanosecond
.
The year
is 0-padded to a minimum of 4 digits. week
, hours
, minutes
, seconds
are 0-padded to a minimum of 2 digits. nanoseconds
is 0-padded to a minimum of 9 digits.
The week
is the ISO week as calculated by .weekOfYear
and the weekday
is the ISO week-day as
calculated by .dayOfWeek
. The year
may be one year before/after the .year
property of the
CivilDateTime
if the specified date is part of the last week of the previous year or the first
week of the following year.
.toOrdinalDateTimeString()
creates an ISO-8601 compliant strung in the format:
year
-day-of-year
Thour
:minute
:second
.nanosecond
.
The year
is 0-padded to a minimum of 4 digits. dof-of-year
, hours
, minutes
, seconds
are 0-padded to a minimum of 2 digits. nanoseconds
is 0-padded to a minimum of 9 digits.
The day-of-year
is the ordinal day as calculated by .dayOfYear
.
Creates a new CivilDateTime
by parsing an ISO-8601 string in the format created by .toDateTimeString()
.
Creates a new CivilDateTime
by parsing an ISO-8601 string in the format created by .toWeekDateTimeString()
.
Creates a new CivilDateTime
by parsing an ISO-8601 string in the format created by .toOrdinalDateTimeString()
.
Creates a new CivilDateTime
by parsing an ISO-8601 string in the one of the formats created .toDateTimeString()
, .toWeekDateTimeString()
or .toOrdinalDateTimeString()
.