Skip to main content

Module datetime

Module datetime 

Source
Expand description

Dates as the database stores them: Y-m-d H:i:s.v in the default timezone (FORMAT_DB), and as the API shows them, with the offset (FORMAT_TZ).

Dates are php_std::datetime::DateTime, a port of PHP’s own date library, so parsing, timezone conversion and formatting are PHP’s.

PHP: Utopia\Database\DateTime. PHP’s default timezone (date_default_timezone_get()) is UTC, as Appwrite sets it; here it is UTC.

use utopia_database::datetime;

assert_eq!(datetime::set_timezone("2024-01-02 03:04:05.678+02:00").unwrap(), "2024-01-02 01:04:05.678");
assert_eq!(datetime::format_tz(Some("2024-01-02 01:04:05.678")).as_deref(), Some("2024-01-02T01:04:05.678+00:00"));

Constants§

FORMAT_DB
How the database stores dates (DateTime::$formatDb).
FORMAT_TZ
How dates are shown with their offset (DateTime::$formatTz).

Functions§

add_seconds
Adds seconds (negative to subtract) to date, and returns it in the database format.
format
date in the database format (FORMAT_DB).
format_tz
value with its offset (FORMAT_TZ); value itself when it is not a date, and None for None.
now
The current time in the database format.
now_after
The current time in the database format, made later than previous: when previous is not before now (a clock that went back, or two writes within one millisecond), one millisecond after previous.
set_timezone
datetime (any string PHP’s DateTime parses) converted to the default timezone, in the database format.