DateTime is a specific date and time, which is aligned towards the UTC timezone.
Methods
Creates a new DateTime with epoch time. Epoch time is Midnight, 1 January, 1970 (UTC).
Creates a new DateTime with the actual utc time.
let dt = new_utc;
assert_eq!;
Return the date as iso8601 encoded string.
Example: 1997-11-21T09:55:06.000000000-06:00
This function tries to parse the DateTime from a string. Multiple formats are tried to be parsed based on the following order:
- json formatted DateTime string
- psql formatted string
- iso8601 formatted string
- local time formatted string
Return the DateTime as local user readable string.
Format: "[year]-[month]-[day], [hour]:[minute]:[second]"
Example: "2023-10-19, 11:35:29"
Tries to parse DateTime from a local user readable string.
Format: "[year]-[month]-[day], [hour]:[minute]:[second]"
Example: "2023-10-19, 11:35:29"
let dt = from_local_string?;
assert_eq!;
Set the year of the DateTime to the given number. When the number is unrealistic, this function returns an error.
Returns the month of the DateTime as number. Janurary is a 1 and December is a 12
Set the month of the DateTime to the given number. Janurary is a 1 and December is a 12
Returns the day of the DateTime as number. The returned value will always be in the range 1..=31.
Set the month of the DateTime to the given number. The number need to be in the range of 1..=31.
Set the minute of the DateTime to the given number.
Set the second of the DateTime to the given number.
Returns the time offset to utc as Duration.
let utc = new_utc;
assert_eq!;
let local = new;
assert!;
Replaces the offset leaves the date and time unchanged.
let utc = new_utc;
assert_eq!;
utc.replace_offset;
assert_eq!;
Returns the difference of full days between two DateTimes
Protocols
let output = value + b
The add operation for adding a Duration to a DateTime.
Example
let dt = new_epoch;
let one = from_days;
let res = dt + one;
assert_eq!;
value += b
The add assign operation for Duration to a Datetime.
Example
let dt = new_epoch;
dt += from_days;
assert_eq!;
let output = value - b
The sub operation for Duration from a Datetime.
Example subtract two DateTimes
let dt1 = from_local_string?;
let dt2 = from_local_string?;
let res = dt2 - dt1;
assert_eq!;
Example subtract a Duration
let dt = from_local_string?;
let one = from_days;
let res = dt - one;
assert_eq!;
value -= b
The sub assign operation for Duration from a Datetime.
Example
let dt = from_local_string?;
dt -= from_days;
assert_eq!;