datetime
ModuleDates 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"));Contents
use utopia_database::datetime::add_seconds;pub fn add_seconds(date: &mut DateTime, seconds: i64) -> Result<String>Adds seconds (negative to subtract) to date, and returns it in the
database format.
Fails like PHP for i64::MIN seconds, which PHP's interval parser does
not read as a number (a Kind::DateMalformedIntervalString error).
PHP: DateTime::addSeconds($date, $seconds).
use utopia_database::datetime::format;pub fn format(date: &DateTime) -> Stringdate in the database format (FORMAT_DB).
PHP: DateTime::format($date).
use utopia_database::datetime::format_tz;pub fn format_tz(value: Option<&str>) -> Option<String>value with its offset (FORMAT_TZ); value itself when it is not
a date, and None for None.
PHP: DateTime::formatTz($dbFormat).
use utopia_database::datetime::now;pub fn now() -> StringThe current time in the database format.
PHP: DateTime::now().
use utopia_database::datetime::now_after;pub fn now_after(previous: Option<&str>) -> Result<String>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.
Fails with the parser's message when previous is not a date
(Kind::Database, wrapping the Kind::DateMalformedString error).
PHP: DateTime::nowAfter($previous).
use utopia_database::datetime::set_timezone;pub fn set_timezone(datetime: impl AsRef<[u8]>) -> Result<String>datetime (any string PHP's DateTime parses) converted to the default
timezone, in the database format.
Fails with the parser's message when datetime is not a date
(Kind::Database, wrapping the Kind::DateMalformedString error).
PHP: DateTime::setTimezone($datetime).
pub const FORMAT_DB: &str = "Y-m-d H:i:s.v";How the database stores dates (DateTime::$formatDb).
pub const FORMAT_TZ: &str = "Y-m-d\\TH:i:s.vP";How dates are shown with their offset (DateTime::$formatTz).