Skip to main content

Module date_format

Module date_format 

Source
Expand description

The date-time text format of the BCS API, for use with #[serde(with = "...")].

The broker sends and wants UTC date-times as ISO 8601 text with milliseconds and a Z, for example 2026-10-19T07:05:00.000Z. All date-times of the API are UTC (broker docs). Use #[serde(with = "brokapi_bcs_protocol::utils::date_format")] on a DateTime<Utc> field, date_format::option on an Option<DateTime<Utc>>, and moex where the broker names the “Moscow Exchange format” (it is the same text format, see there).

§Examples

use brokapi_bcs_protocol::utils::date_format;
use chrono::{DateTime, TimeZone, Utc};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Bar {
    #[serde(with = "date_format")]
    time: DateTime<Utc>,
}

let bar = Bar { time: Utc.with_ymd_and_hms(2026, 10, 19, 7, 5, 0).unwrap() };
let text = serde_json::to_string(&bar)?;
assert_eq!(text, r#"{"time":"2026-10-19T07:05:00.000Z"}"#);
assert_eq!(serde_json::from_str::<Bar>(&text)?, bar);

Modules§

moex
The format the broker docs call the Moscow Exchange format: yyyy-MM-dd'T'HH:mm:ss.SSSX.
option
The same format for an optional date-time (Option<DateTime<Utc>>).

Functions§

deserialize
Reads a date-time text into a UTC DateTime.
now_millis
The current time as milliseconds since the Unix epoch (UTC).
serialize
Writes a UTC date-time as text with milliseconds and a Z, for example 2026-10-19T07:05:00.000Z.