1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! # utcize
//! **Normalize any datetime input to UTC. Automatically.**
//!
//! `utcize` is a lightweight Rust library for normalizing various datetime inputs into
//! a `DateTime<Utc>` using the [`chrono`](https://crates.io/crates/chrono) crate.
//!
//! ## Features
//!
//! - Automatic format detection (RFC 3339, RFC 2822, ISO 8601, Unix timestamps: seconds, milliseconds, microseconds, nanoseconds).
//! - Supports both European-style (`dd-mm-yyyy`) and US-style (`mm-dd-yyyy`) formats.
//! - Handles fixed timezone offsets (e.g., `+07:00`, `-0800`) and IANA timezones (e.g., `Asia/Jakarta`, `Europe/Berlin`).
//! - Fallback timezone support for naive datetime strings (without timezone).
//! - Ambiguity handling for local times during daylight saving transitions.
//! - Easy to extend with custom formats.
//!
//! ## Example
//!
//! ```rust
//! use utcize::datetime::utcize;
//!
//! let dt = utcize::<&str>("2023-06-01 10:00:00", "Asia/Jakarta", false, None).unwrap();
//! assert_eq!(dt.to_rfc3339(), "2023-06-01T03:00:00+00:00");
//!
//! let res = utcize::<&str>("2023-06-01 10:00:00", "+07:00", false, None).unwrap();
//! assert_eq!(res.to_rfc3339(), "2023-06-01T03:00:00+00:00");
//!
//! let dt = utcize::<&str>("01-06-2023 10:00:00", "Europe/Paris", true, None).unwrap();
//! assert_eq!(dt.to_rfc3339(), "2023-06-01T08:00:00+00:00");
//!
//! let custom_format = ["%Y|%m|%d %H:%M", "%d.%B.%Y %H:%M"];
//!
//! let dt = utcize("2023|06|01 10:00", "Asia/Jakarta", false, Some(&custom_format)).unwrap();
//! assert_eq!(dt.to_rfc3339(), "2023-06-01T03:00:00+00:00");
//!
//! let dt = utcize("2023|06|01 10:00", "+07:00", false, Some(&custom_format)).unwrap();
//! assert_eq!(dt.to_rfc3339(), "2023-06-01T03:00:00+00:00");
//!
//! let dt = utcize("01.June.2023 10:00", "Europe/Berlin", true, Some(&custom_format)).unwrap();
//! assert_eq!(dt.to_rfc3339(), "2023-06-01T08:00:00+00:00")
//! ```
//!
//! ---
//!
//! ## License
//!
//! - Licensed under Apache License, Version 2.0 [LICENSE](http://www.apache.org/licenses/LICENSE-2.0.txt)
//!
//! ---
//!
//! ## Author
//!
//! - Created and maintained by [Jerry Maheswara](https://github.com/jerry-maheswara-github)
//!
//! ---
//!
//! ## Built with Love in Rust
//!
//! - This project is built with ❤️ using **Rust** — a systems programming language that is safe, fast, and concurrent. Rust is the perfect choice for building reliable and efficient applications.
//!
//! ---
/// Main module for parsing and normalizing datetime strings to UTC.
/// Error definitions for datetime parsing and conversion.
/// Internal data types representing parsed time, timezone kinds, and epoch types.
/// Collection of datetime format strings used for flexible parsing.
/// Functions for parsing and validating fixed and IANA timezones.