• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zbraniecki / icu4x / 13958601093

19 Mar 2025 04:17PM UTC coverage: 74.164% (-1.5%) from 75.71%
13958601093

push

github

web-flow
Clean up properties docs (#6315)

58056 of 78281 relevant lines covered (74.16%)

819371.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/components/datetime/src/combo.rs
1
// This file is part of ICU4X. For terms of use, please see the file
2
// called LICENSE at the top level of the ICU4X source tree
3
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4

5
use crate::{provider::neo::*, scaffold::*};
6

7
/// Struct for combining date/time fields with zone fields.
8
///
9
/// This struct produces "composite field sets" as defined in UTS 35.
10
/// See [`fieldsets`](crate::fieldsets).
11
///
12
/// # Examples
13
///
14
/// Only one way to construct a combo field set (in this case, weekday with location-based zone):
15
///
16
/// ```
17
/// use icu::datetime::fieldsets::{zone::Location, Combo, E};
18
///
19
/// let field_set = E::long().zone(Location);
20
/// ```
21
///
22
/// Format the weekday, hour, and location-based zone:
23
///
24
/// ```
25
/// use icu::datetime::fieldsets::{zone::Location, Combo, ET};
26
/// use icu::datetime::input::ZonedDateTime;
27
/// use icu::datetime::DateTimeFormatter;
28
/// use icu::locale::locale;
29
/// use icu::time::zone::IanaParser;
30
/// use writeable::assert_writeable_eq;
31
///
32
/// // Note: Combo type can be elided, but it is shown here for demonstration
33
/// let formatter = DateTimeFormatter::<Combo<ET, Location>>::try_new(
34
///     locale!("en-US").into(),
35
///     ET::short().hm().zone(Location),
36
/// )
37
/// .unwrap();
38
///
39
/// let zdt = ZonedDateTime::try_location_only_from_str(
40
///     "2024-10-18T15:44[America/Los_Angeles]",
41
///     formatter.calendar(),
42
///     IanaParser::new(),
43
/// )
44
/// .unwrap();
45
///
46
/// assert_writeable_eq!(
47
///     formatter.format(&zdt),
48
///     "Fri, 3:44 PM Los Angeles Time"
49
/// );
50
/// ```
51
///
52
/// Same thing with a fixed calendar formatter:
53
///
54
/// ```
55
/// use icu::calendar::Gregorian;
56
/// use icu::datetime::fieldsets::{zone::Location, Combo, ET};
57
/// use icu::datetime::input::ZonedDateTime;
58
/// use icu::datetime::FixedCalendarDateTimeFormatter;
59
/// use icu::locale::locale;
60
/// use icu::time::zone::IanaParser;
61
/// use writeable::assert_writeable_eq;
62
///
63
/// // Note: Combo type can be elided, but it is shown here for demonstration
64
/// let formatter =
65
///     FixedCalendarDateTimeFormatter::<_, Combo<ET, Location>>::try_new(
66
///         locale!("en-US").into(),
67
///         ET::short().hm().zone(Location),
68
///     )
69
///     .unwrap();
70
///
71
/// let zdt = ZonedDateTime::try_location_only_from_str(
72
///     "2024-10-18T15:44[America/Los_Angeles]",
73
///     Gregorian,
74
///     IanaParser::new(),
75
/// )
76
/// .unwrap();
77
///
78
/// assert_writeable_eq!(
79
///     formatter.format(&zdt),
80
///     "Fri, 3:44 PM Los Angeles Time"
81
/// );
82
/// ```
83
///
84
/// Mix a dynamic [`DateFieldSet`](crate::fieldsets::enums::DateFieldSet)
85
/// with a static time zone:
86
///
87
/// ```
88
/// use icu::datetime::fieldsets::{
89
///     enums::DateFieldSet, zone::GenericShort, Combo, YMD,
90
/// };
91
/// use icu::datetime::input::ZonedDateTime;
92
/// use icu::datetime::DateTimeFormatter;
93
/// use icu::locale::locale;
94
/// use icu::time::zone::IanaParser;
95
/// use writeable::assert_writeable_eq;
96
///
97
/// // Note: Combo type can be elided, but it is shown here for demonstration
98
/// let formatter =
99
///     DateTimeFormatter::<Combo<DateFieldSet, GenericShort>>::try_new(
100
///         locale!("en-US").into(),
101
///         DateFieldSet::YMD(YMD::long()).zone(GenericShort),
102
///     )
103
///     .unwrap();
104
///
105
/// let zdt = ZonedDateTime::try_location_only_from_str(
106
///     "2024-10-18T15:44[America/Los_Angeles]",
107
///     formatter.calendar(),
108
///     IanaParser::new(),
109
/// )
110
/// .unwrap();
111
///
112
/// assert_writeable_eq!(formatter.format(&zdt), "October 18, 2024 PT");
113
/// ```
114
///
115
/// Format with a time of day and long time zone:
116
///
117
/// ```
118
/// use icu::calendar::Gregorian;
119
/// use icu::datetime::fieldsets::{zone::SpecificLong, T};
120
/// use icu::datetime::input::ZonedDateTime;
121
/// use icu::datetime::FixedCalendarDateTimeFormatter;
122
/// use icu::locale::locale;
123
/// use icu::time::zone::{IanaParser, VariantOffsetsCalculator};
124
/// use writeable::assert_writeable_eq;
125
///
126
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
127
///     locale!("en-US").into(),
128
///     T::medium().zone(SpecificLong),
129
/// )
130
/// .unwrap();
131
///
132
/// let zdt = ZonedDateTime::try_from_str(
133
///     "2024-10-18T15:44-0700[America/Los_Angeles]",
134
///     Gregorian,
135
///     IanaParser::new(),
136
///     VariantOffsetsCalculator::new(),
137
/// )
138
/// .unwrap();
139
///
140
/// assert_writeable_eq!(
141
///     formatter.format(&zdt),
142
///     "3:44:00 PM Pacific Daylight Time"
143
/// );
144
/// ```
145
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
2✔
146
pub struct Combo<DT, Z> {
147
    date_time_field_set: DT,
1✔
148
    zone_field_set: Z,
1✔
149
}
150

151
impl<DT, Z> Combo<DT, Z> {
152
    #[inline]
153
    pub(crate) const fn new(date_time_field_set: DT, zone_field_set: Z) -> Self {
132✔
154
        Self {
132✔
155
            date_time_field_set,
156
            zone_field_set,
157
        }
158
    }
132✔
159
}
160

161
impl<DT, Z> UnstableSealed for Combo<DT, Z> {}
162

163
impl<DT, Z> Combo<DT, Z> {
164
    #[inline]
165
    pub(crate) fn dt(self) -> DT {
6✔
166
        self.date_time_field_set
6✔
167
    }
6✔
168
    #[inline]
169
    pub(crate) fn z(self) -> Z {
6✔
170
        self.zone_field_set
×
171
    }
6✔
172
}
173

174
impl<DT, Z> DateTimeNamesMarker for Combo<DT, Z>
175
where
176
    DT: DateTimeNamesMarker,
177
    Z: DateTimeNamesMarker,
178
{
179
    type YearNames = DT::YearNames;
180
    type MonthNames = DT::MonthNames;
181
    type WeekdayNames = DT::WeekdayNames;
182
    type DayPeriodNames = DT::DayPeriodNames;
183
    type ZoneEssentials = Z::ZoneEssentials;
184
    type ZoneLocations = Z::ZoneLocations;
185
    type ZoneLocationsRoot = Z::ZoneLocationsRoot;
186
    type ZoneExemplars = Z::ZoneExemplars;
187
    type ZoneExemplarsRoot = Z::ZoneExemplarsRoot;
188
    type ZoneGenericLong = Z::ZoneGenericLong;
189
    type ZoneGenericShort = Z::ZoneGenericShort;
190
    type ZoneStandardLong = Z::ZoneStandardLong;
191
    type ZoneSpecificLong = Z::ZoneSpecificLong;
192
    type ZoneSpecificShort = Z::ZoneSpecificShort;
193
    type MetazoneLookup = Z::MetazoneLookup;
194
}
195

196
impl<DT, Z> DateTimeMarkers for Combo<DT, Z>
197
where
198
    DT: DateTimeMarkers,
199
    Z: DateTimeMarkers,
200
{
201
    type D = DT::D;
202
    type T = DT::T;
203
    type Z = Z::Z;
204
    type GluePatternV1 = datetime_marker_helper!(@glue, yes);
205
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc