Rust

datetime

Module

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).

Rust
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;
Rust
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.

use utopia_database::datetime::format;
Rust
pub fn format(date: &DateTime) -> String

date in the database format (FORMAT_DB).

use utopia_database::datetime::format_tz;
Rust
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.

use utopia_database::datetime::now;
Rust
pub fn now() -> String

The current time in the database format.

use utopia_database::datetime::set_timezone;
Rust
pub fn set_timezone(datetime: impl AsRef<[u8]>) -> Result<String>

Fails with the parser's message when datetime is not a date (Kind::Database).

Rust
pub const FORMAT_DB: &str = "Y-m-d H:i:s.v"

How the database stores dates (DateTime::$formatDb).

Rust
pub const FORMAT_TZ: &str = "Y-m-d\\TH:i:s.vP"

How dates are shown with their offset (DateTime::$formatTz).