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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Parts of a formatted date/time.
//!
//! # Examples
//!
//! ```
//! use icu::calendar::Gregorian;
//! use icu::calendar::{Date, Time};
//! use icu::datetime::parts as datetime_parts;
//! use icu::datetime::fieldsets;
//! use icu::datetime::options::FractionalSecondDigits;
//! use icu::datetime::options::TimePrecision;
//! use icu::datetime::DateTimeFormatter;
//! use icu::decimal::parts as decimal_parts;
//! use icu::locale::locale;
//! use icu::timezone::IxdtfParser;
//! use writeable::assert_writeable_parts_eq;
//!
//! let dtf = DateTimeFormatter::try_new(
//!     locale!("en-u-ca-buddhist").into(),
//!     fieldsets::YMDT::medium().with_time_precision(TimePrecision::SecondExact(FractionalSecondDigits::F2)).with_zone_specific(),
//! )
//! .unwrap();
//!
//! let dtz = IxdtfParser::new().try_from_str("2023-11-20T11:35:03.5+00:00[Europe/London]").unwrap();
//!
//! // Missing data is filled in on a best-effort basis, and an error is signaled.
//! assert_writeable_parts_eq!(
//!     dtf.format_any_calendar(&dtz),
//!     "Nov 20, 2566 BE, 11:35:03.50 AM GMT",
//!     [
//!         (0, 3, datetime_parts::MONTH),
//!         (4, 6, decimal_parts::INTEGER),
//!         (4, 6, datetime_parts::DAY),
//!         (8, 12, decimal_parts::INTEGER),
//!         (8, 12, datetime_parts::YEAR),
//!         (13, 15, datetime_parts::ERA),
//!         (17, 19, decimal_parts::INTEGER),
//!         (17, 19, datetime_parts::HOUR),
//!         (20, 22, decimal_parts::INTEGER),
//!         (20, 22, datetime_parts::MINUTE),
//!         (23, 28, datetime_parts::SECOND),
//!         (23, 25, decimal_parts::INTEGER),
//!         (25, 26, decimal_parts::DECIMAL),
//!         (26, 28, decimal_parts::FRACTION),
//!         // note: from 28 to 31 is a NNBSP
//!         (31, 33, datetime_parts::DAY_PERIOD),
//!         (34, 37, datetime_parts::TIME_ZONE_NAME),
//!     ]
//! );
//! ```

use writeable::Part;

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const ERA: Part = Part {
    category: "datetime",
    value: "era",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const YEAR: Part = Part {
    category: "datetime",
    value: "year",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const RELATED_YEAR: Part = Part {
    category: "datetime",
    value: "relatedYear",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const YEAR_NAME: Part = Part {
    category: "datetime",
    value: "yearName",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const MONTH: Part = Part {
    category: "datetime",
    value: "month",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const DAY: Part = Part {
    category: "datetime",
    value: "day",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const WEEKDAY: Part = Part {
    category: "datetime",
    value: "weekday",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const DAY_PERIOD: Part = Part {
    category: "datetime",
    value: "dayPeriod",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const HOUR: Part = Part {
    category: "datetime",
    value: "hour",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const MINUTE: Part = Part {
    category: "datetime",
    value: "minute",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const SECOND: Part = Part {
    category: "datetime",
    value: "second",
};

/// A [`Part`] used by [`FormattedDateTime`](super::FormattedDateTime).
pub const TIME_ZONE_NAME: Part = Part {
    category: "datetime",
    value: "timeZoneName",
};