DateTimes extension

Provides functions for working with in-built DateTimes.

These functions should only be used when it is not feasible to use sugar.time.

on

Properties

dayOfYear int
The ordinal day of the year.
no setter
daysInMonth int
The number of days in the month, taking leap years into account.
no setter
daysSinceEpoch int
The days since Unix epoch.
no setter
firstDayOfMonth DateTime
The first day of the month.
no setter
firstDayOfWeek DateTime
The first day of the week.
no setter
lastDayOfMonth DateTime
The last day of the month.
no setter
lastDayOfWeek DateTime
The last day of the week.
no setter
leapYear bool
Whether the is year is a leap year.
no setter
microsecondsSinceMidnight int
The time as microseconds since midnight.
no setter
millisecondsSinceMidnight int
The time as milliseconds since midnight.
no setter
offset Offset
The offset.
no setter
weekOfYear int
The ordinal week of the year.
no setter

Methods

ceil(TemporalUnit unit, int value) DateTime
Returns a copy of this ceiled to the nearest unit and value.
floor(TemporalUnit unit, int value) DateTime
Returns a copy of this floored to the nearest unit and value.
minus({int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) DateTime
Returns a copy of this with the units of time subtracted.
plus({int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) DateTime
Returns a copy of this with the units of time added.
round(TemporalUnit unit, int value) DateTime
Returns a copy of this rounded to the nearest unit and value.
toDateString() String
Formats this DateTime's date as a ISO-8601 date, ignoring the time.
toTimeString() String
Formats this DateTime's time as a ISO-8601 time, ignoring the date.
truncate({required TemporalUnit to}) DateTime
Returns a copy of this truncated to the TemporalUnit.

Operators

operator +(Period period) DateTime
Returns a copy of this with the period added.
operator -(Period period) DateTime
Returns a copy of this with the period subtracted.