time_util/
lib.rs

1// Copyright (C) 2019-2021 Daniel Mueller <deso@posteo.net>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4//! A crate for more or less frequently used time parsing and formatting
5//! functionality.
6//!
7//! The crate revolves around the `std::time::SystemTime` type in that
8//! we attempt to convert into that or use this as the base to convert
9//! from. We treat such a time as having no associated time zone. Think
10//! of it as being in UTC.
11
12#[allow(clippy::let_and_return)]
13
14#[cfg(feature = "math")]
15mod math;
16#[cfg(any(test, feature = "chrono"))]
17mod parse;
18#[cfg(any(test, feature = "chrono"))]
19mod print;
20#[cfg(any(test, all(feature = "chrono", feature = "serde")))]
21mod serde;
22
23// We treat chrono-tz as optional on top of chrono.
24#[cfg(not(any(feature = "math", feature = "chrono", feature = "serde")))]
25compile_error!("Please specify one of the features: math, chrono, or serde");
26
27#[cfg(feature = "math")]
28pub use crate::math::{
29  days_back,
30  days_back_from,
31  next_day,
32  tomorrow,
33};
34
35#[cfg(feature = "chrono")]
36pub use crate::parse::{
37  parse_system_time_from_date_str,
38  parse_system_time_from_str,
39};
40
41#[cfg(feature = "chrono")]
42pub use crate::print::{
43  print_system_time_to_iso8601_date,
44  print_system_time_to_rfc3339,
45  print_system_time_to_rfc3339_with_nanos,
46};
47
48#[cfg(all(feature = "chrono", feature = "serde"))]
49pub use crate::serde::{
50  optional_system_time_from_str,
51  optional_system_time_to_rfc3339,
52  optional_system_time_to_rfc3339_with_nanos,
53  system_time_from_date_str,
54  system_time_from_millis,
55  system_time_from_secs,
56  system_time_from_str,
57  system_time_to_millis,
58  system_time_to_rfc3339,
59  system_time_to_rfc3339_with_nanos,
60};
61
62#[cfg(all(feature = "chrono", feature = "chrono-tz", feature = "serde"))]
63pub use crate::serde::{
64  system_time_from_millis_in_new_york,
65  system_time_to_millis_in_new_york,
66};