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) todate, and returns it in the database format. - format
datein the database format (FORMAT_DB).- format_
tz valuewith its offset (FORMAT_TZ);valueitself when it is not a date, andNoneforNone.- now
- The current time in the database format.
- now_
after - The current time in the database format, made later than
previous: whenpreviousis not before now (a clock that went back, or two writes within one millisecond), one millisecond afterprevious. - set_
timezone datetime(any string PHP’sDateTimeparses) converted to the default timezone, in the database format.