datetime_literal

Crates.iodatetime_literal
lib.rsdatetime_literal
version0.1.3
created_at2025-01-09 22:08:21.385467+00
updated_at2025-01-21 21:08:02.037559+00
descriptionA macro for creating chrono::DateTime instances.
homepage
repositoryhttps://github.com/avl/datetime_literal
max_upload_size
id1510624
size5,215
Anders Musikka (avl)

documentation

README

Datetime Literal

This is an extremely simple crate that provides a macro for easily creating instances of chrono's DateTime:

Examples:

assert_eq!(
    datetime!(2024-01-02 13:14:15),
    "2024-01-02T13:14:15".parse().unwrap()
);
assert_eq!(
    datetime!(2024-01-02 13:14:15 Z),
    "2024-01-02T13:14:15Z".parse::<chrono::DateTime<chrono::Utc>>().unwrap()
);

assert_eq!(
    datetime!(2024-01-02 T 13:14:15),
    "2024-01-02T13:14:15".parse().unwrap()
);
assert_eq!(
    datetime!(2024-01-02 T 13:14:15 Z),
    "2024-01-02T13:14:15Z".parse::<chrono::DateTime<chrono::Utc>>().unwrap()
);

assert_eq!(
    datetime!(2024-01-02),
    "2024-01-02T00:00:00".parse().unwrap()
);
assert_eq!(
    datetime!(2024-01-02 Z),
    "2024-01-02T00:00:00Z".parse::<chrono::DateTime<chrono::Utc>>().unwrap()
);

Note! Because of how rust macros work, you must leave space before/after 'T', and before 'Z'.

Commit count: 9

cargo fmt