/rust/registry/src/index.crates.io-1949cf8c6b5b557f/icu_datetime-1.5.1/src/input.rs
Line | Count | Source |
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 | | //! A collection of utilities for representing and working with dates as an input to |
6 | | //! formatting operations. |
7 | | |
8 | | use crate::provider::time_zones::{MetazoneId, TimeZoneBcp47Id}; |
9 | | use icu_calendar::any_calendar::AnyCalendarKind; |
10 | | use icu_calendar::week::{RelativeUnit, WeekCalculator}; |
11 | | use icu_calendar::Calendar; |
12 | | use icu_calendar::{AsCalendar, Date, DateTime, Iso}; |
13 | | use icu_timezone::{CustomTimeZone, GmtOffset, ZoneVariant}; |
14 | | |
15 | | // TODO(#2630) fix up imports to directly import from icu_calendar |
16 | | pub(crate) use icu_calendar::types::{ |
17 | | DayOfMonth, DayOfWeekInMonth, DayOfYearInfo, FormattableMonth, FormattableYear, IsoHour, |
18 | | IsoMinute, IsoSecond, IsoWeekday, NanoSecond, Time, WeekOfMonth, WeekOfYear, |
19 | | }; |
20 | | pub(crate) use icu_calendar::CalendarError; |
21 | | |
22 | | /// Representation of a formattable calendar date. Supports dates in any calendar system that uses |
23 | | /// solar days indexed by an era, year, month, and day. |
24 | | /// |
25 | | /// All fields are optional. If a field is not present but is required when formatting, an error |
26 | | /// result will be returned from the formatter. |
27 | | /// |
28 | | /// All data represented in [`DateInput`] should be locale-agnostic. |
29 | | pub trait DateInput { |
30 | | /// The calendar this date relates to |
31 | | type Calendar: Calendar; |
32 | | /// Gets the era and year input. |
33 | | fn year(&self) -> Option<FormattableYear>; |
34 | | |
35 | | /// Gets the month input. |
36 | | fn month(&self) -> Option<FormattableMonth>; |
37 | | |
38 | | /// Gets the day input. |
39 | | fn day_of_month(&self) -> Option<DayOfMonth>; |
40 | | |
41 | | /// Gets the weekday input. |
42 | | fn iso_weekday(&self) -> Option<IsoWeekday>; |
43 | | |
44 | | /// Gets information on the position of the day within the year. |
45 | | fn day_of_year_info(&self) -> Option<DayOfYearInfo>; |
46 | | |
47 | | /// Gets the kind of calendar this date is for, if associated with [`AnyCalendar`] |
48 | | /// In most cases you'll probably want to return [`AnyCalendarKind::Iso`]. |
49 | | /// |
50 | | /// [`AnyCalendar`]: icu_calendar::any_calendar::AnyCalendar |
51 | | fn any_calendar_kind(&self) -> Option<AnyCalendarKind>; |
52 | | |
53 | | /// Converts date to ISO |
54 | | fn to_iso(&self) -> Date<Iso>; |
55 | | } |
56 | | |
57 | | /// Representation of a time of day according to ISO-8601 conventions. Always indexed from |
58 | | /// midnight, regardless of calendar system. |
59 | | /// |
60 | | /// All fields are optional. If a field is not present but is required when formatting, an error |
61 | | /// result will be returned from the formatter. |
62 | | /// |
63 | | /// All data represented in [`IsoTimeInput`] should be locale-agnostic. |
64 | | pub trait IsoTimeInput { |
65 | | /// Gets the hour input. |
66 | | fn hour(&self) -> Option<IsoHour>; |
67 | | |
68 | | /// Gets the minute input. |
69 | | fn minute(&self) -> Option<IsoMinute>; |
70 | | |
71 | | /// Gets the second input. |
72 | | fn second(&self) -> Option<IsoSecond>; |
73 | | |
74 | | /// Gets the nanosecond input. |
75 | | fn nanosecond(&self) -> Option<NanoSecond>; |
76 | | } |
77 | | |
78 | | /// Representation of a formattable time zone. |
79 | | /// |
80 | | /// Only the [`GmtOffset`] is required, since it is the final format fallback. |
81 | | /// |
82 | | /// All data represented in [`TimeZoneInput`] should be locale-agnostic. |
83 | | pub trait TimeZoneInput { |
84 | | /// The GMT offset in Nanoseconds. |
85 | | fn gmt_offset(&self) -> Option<GmtOffset>; |
86 | | |
87 | | /// The IANA time-zone identifier. |
88 | | fn time_zone_id(&self) -> Option<TimeZoneBcp47Id>; |
89 | | |
90 | | /// The metazone identifier. |
91 | | fn metazone_id(&self) -> Option<MetazoneId>; |
92 | | |
93 | | /// The time variant (e.g. "daylight", "standard") |
94 | | fn zone_variant(&self) -> Option<ZoneVariant>; |
95 | | } |
96 | | |
97 | | /// A combination of a formattable calendar date and ISO time. |
98 | | /// |
99 | | /// # Examples |
100 | | /// |
101 | | /// If the trait does not return all required fields, an error output will occur: |
102 | | /// |
103 | | /// ``` |
104 | | /// use icu::calendar::*; |
105 | | /// use icu::calendar::types::*; |
106 | | /// use icu::datetime::input::*; |
107 | | /// use icu::datetime::{DateTimeWriteError, TypedDateTimeNames}; |
108 | | /// use icu::datetime::fields::{Field, FieldLength, FieldSymbol, Weekday}; |
109 | | /// use icu::datetime::neo_pattern::DateTimePattern; |
110 | | /// use icu::locid::locale; |
111 | | /// use writeable::assert_try_writeable_eq; |
112 | | /// |
113 | | /// struct Empty; |
114 | | /// |
115 | | /// impl DateInput for Empty { |
116 | | /// type Calendar = Gregorian; |
117 | | /// fn year(&self) -> Option<FormattableYear> { None } |
118 | | /// fn month(&self) -> Option<FormattableMonth> { None } |
119 | | /// fn day_of_month(&self) -> Option<DayOfMonth> { None } |
120 | | /// fn iso_weekday(&self) -> Option<IsoWeekday> { None } |
121 | | /// fn day_of_year_info(&self) -> Option<DayOfYearInfo> { None } |
122 | | /// fn any_calendar_kind(&self) -> Option<AnyCalendarKind> { None } |
123 | | /// fn to_iso(&self) -> icu::calendar::Date<Iso> { todo!() } |
124 | | /// } |
125 | | /// |
126 | | /// impl IsoTimeInput for Empty { |
127 | | /// fn hour(&self) -> Option<IsoHour> { None } |
128 | | /// fn minute(&self) -> Option<IsoMinute> { None } |
129 | | /// fn second(&self) -> Option<IsoSecond> { None } |
130 | | /// fn nanosecond(&self) -> Option<NanoSecond> { None } |
131 | | /// } |
132 | | /// |
133 | | /// // Create an instance that can format abbreviated month, weekday, and day period names: |
134 | | /// let mut names: TypedDateTimeNames<Gregorian> = |
135 | | /// TypedDateTimeNames::try_new(&locale!("en").into()).unwrap(); |
136 | | /// |
137 | | /// // Create a pattern from a pattern string: |
138 | | /// let pattern_str = "'It is:' E MMM d y G 'at' h:mm:ssSSS a"; |
139 | | /// let pattern: DateTimePattern = pattern_str.parse().unwrap(); |
140 | | /// |
141 | | /// // The pattern string contains lots of symbols, but our DateTimeInput is empty! |
142 | | /// let mut buffer = String::new(); |
143 | | /// // Missing data is filled in on a best-effort basis, and an error is signaled. |
144 | | /// assert_try_writeable_eq!( |
145 | | /// names.with_pattern(&pattern).format(&Empty), |
146 | | /// "It is: {E} {M} {d} {y} {G} at {h}:{m}:{s}{S} {a}", |
147 | | /// Err(DateTimeWriteError::MissingInputField("iso_weekday")) |
148 | | /// ); |
149 | | /// ``` |
150 | | pub trait DateTimeInput: DateInput + IsoTimeInput {} |
151 | | |
152 | | impl<T> DateTimeInput for T where T: DateInput + IsoTimeInput {} |
153 | | |
154 | | /// A formattable calendar date and ISO time that takes the locale into account. |
155 | | pub trait LocalizedDateTimeInput<T: DateTimeInput> { |
156 | | /// A reference to this instance's [`DateTimeInput`]. |
157 | | fn datetime(&self) -> &T; |
158 | | |
159 | | /// The week of the month. |
160 | | /// |
161 | | /// For example, January 1, 2021 is part of the first week of January. |
162 | | fn week_of_month(&self) -> Result<WeekOfMonth, CalendarError>; |
163 | | |
164 | | /// The week number of the year and the corresponding year. |
165 | | /// |
166 | | /// For example, December 31, 2020 is part of the first week of 2021. |
167 | | fn week_of_year(&self) -> Result<(FormattableYear, WeekOfYear), CalendarError>; |
168 | | |
169 | | /// The day of week in this month. |
170 | | /// |
171 | | /// For example, July 8, 2020 is the 2nd Wednesday of July. |
172 | | fn day_of_week_in_month(&self) -> Result<DayOfWeekInMonth, CalendarError>; |
173 | | |
174 | | /// TODO(#487): Implement flexible day periods. |
175 | | fn flexible_day_period(&self); |
176 | | } |
177 | | |
178 | | /// A [`DateTimeInput`] type with all of the fields pre-extracted |
179 | | /// |
180 | | /// See [`DateTimeInput`] for documentation on individual fields |
181 | | #[derive(Default, Debug, Copy, Clone)] |
182 | | pub(crate) struct ExtractedDateTimeInput { |
183 | | year: Option<FormattableYear>, |
184 | | month: Option<FormattableMonth>, |
185 | | day_of_month: Option<DayOfMonth>, |
186 | | iso_weekday: Option<IsoWeekday>, |
187 | | day_of_year_info: Option<DayOfYearInfo>, |
188 | | any_calendar_kind: Option<AnyCalendarKind>, |
189 | | hour: Option<IsoHour>, |
190 | | minute: Option<IsoMinute>, |
191 | | second: Option<IsoSecond>, |
192 | | nanosecond: Option<NanoSecond>, |
193 | | } |
194 | | |
195 | | /// A [`TimeZoneInput`] type with all of the fields pre-extracted |
196 | | /// |
197 | | /// See [`TimeZoneInput`] for documentation on individual fields |
198 | | #[derive(Debug, Copy, Clone)] |
199 | | pub(crate) struct ExtractedTimeZoneInput { |
200 | | gmt_offset: Option<GmtOffset>, |
201 | | time_zone_id: Option<TimeZoneBcp47Id>, |
202 | | metazone_id: Option<MetazoneId>, |
203 | | zone_variant: Option<ZoneVariant>, |
204 | | } |
205 | | |
206 | | impl ExtractedDateTimeInput { |
207 | | /// Construct given an instance of a [`DateTimeInput`]. |
208 | 0 | pub(crate) fn extract_from<T: DateTimeInput>(input: &T) -> Self { |
209 | 0 | Self { |
210 | 0 | year: input.year(), |
211 | 0 | month: input.month(), |
212 | 0 | day_of_month: input.day_of_month(), |
213 | 0 | iso_weekday: input.iso_weekday(), |
214 | 0 | day_of_year_info: input.day_of_year_info(), |
215 | 0 | any_calendar_kind: input.any_calendar_kind(), |
216 | 0 | hour: input.hour(), |
217 | 0 | minute: input.minute(), |
218 | 0 | second: input.second(), |
219 | 0 | nanosecond: input.nanosecond(), |
220 | 0 | } |
221 | 0 | } Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<icu_datetime::input::ExtractedDateTimeInput> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from::<_> |
222 | | /// Construct given an instance of a [`DateTimeInput`]. |
223 | 0 | pub(crate) fn extract_from_date<T: DateInput>(input: &T) -> Self { |
224 | 0 | Self { |
225 | 0 | year: input.year(), |
226 | 0 | month: input.month(), |
227 | 0 | day_of_month: input.day_of_month(), |
228 | 0 | iso_weekday: input.iso_weekday(), |
229 | 0 | day_of_year_info: input.day_of_year_info(), |
230 | 0 | any_calendar_kind: input.any_calendar_kind(), |
231 | 0 | ..Default::default() |
232 | 0 | } |
233 | 0 | } Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::date::Date<icu_calendar::gregorian::Gregorian>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_date::<_> |
234 | | /// Construct given an instance of a [`DateTimeInput`]. |
235 | 0 | pub(crate) fn extract_from_time<T: IsoTimeInput>(input: &T) -> Self { |
236 | 0 | Self { |
237 | 0 | hour: input.hour(), |
238 | 0 | minute: input.minute(), |
239 | 0 | second: input.second(), |
240 | 0 | nanosecond: input.nanosecond(), |
241 | 0 | ..Default::default() |
242 | 0 | } |
243 | 0 | } Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_time::<icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_time::<icu_calendar::datetime::DateTime<icu_calendar::iso::Iso>> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_time::<icu_calendar::types::Time> Unexecuted instantiation: <icu_datetime::input::ExtractedDateTimeInput>::extract_from_time::<_> |
244 | | } |
245 | | |
246 | | impl ExtractedTimeZoneInput { |
247 | | /// Construct given an instance of a [`ZonedDateTimeInput`]. |
248 | 0 | pub(crate) fn extract_from<T: TimeZoneInput>(input: &T) -> Self { |
249 | 0 | Self { |
250 | 0 | gmt_offset: input.gmt_offset(), |
251 | 0 | time_zone_id: input.time_zone_id(), |
252 | 0 | metazone_id: input.metazone_id(), |
253 | 0 | zone_variant: input.zone_variant(), |
254 | 0 | } |
255 | 0 | } Unexecuted instantiation: <icu_datetime::input::ExtractedTimeZoneInput>::extract_from::<icu_timezone::time_zone::CustomTimeZone> Unexecuted instantiation: <icu_datetime::input::ExtractedTimeZoneInput>::extract_from::<_> |
256 | | } |
257 | | |
258 | | impl DateInput for ExtractedDateTimeInput { |
259 | | /// This actually doesn't matter, by the time we use this |
260 | | /// it's purely internal raw code where calendars are irrelevant |
261 | | type Calendar = icu_calendar::any_calendar::AnyCalendar; |
262 | 0 | fn year(&self) -> Option<FormattableYear> { |
263 | 0 | self.year |
264 | 0 | } |
265 | 0 | fn month(&self) -> Option<FormattableMonth> { |
266 | 0 | self.month |
267 | 0 | } |
268 | 0 | fn day_of_month(&self) -> Option<DayOfMonth> { |
269 | 0 | self.day_of_month |
270 | 0 | } |
271 | 0 | fn iso_weekday(&self) -> Option<IsoWeekday> { |
272 | 0 | self.iso_weekday |
273 | 0 | } |
274 | 0 | fn day_of_year_info(&self) -> Option<DayOfYearInfo> { |
275 | 0 | self.day_of_year_info |
276 | 0 | } |
277 | 0 | fn any_calendar_kind(&self) -> Option<AnyCalendarKind> { |
278 | 0 | self.any_calendar_kind |
279 | 0 | } |
280 | 0 | fn to_iso(&self) -> Date<Iso> { |
281 | 0 | unreachable!("ExtractedDateTimeInput should never be directly passed to DateTimeFormatter") |
282 | | } |
283 | | } |
284 | | |
285 | | impl IsoTimeInput for ExtractedDateTimeInput { |
286 | 0 | fn hour(&self) -> Option<IsoHour> { |
287 | 0 | self.hour |
288 | 0 | } |
289 | 0 | fn minute(&self) -> Option<IsoMinute> { |
290 | 0 | self.minute |
291 | 0 | } |
292 | 0 | fn second(&self) -> Option<IsoSecond> { |
293 | 0 | self.second |
294 | 0 | } |
295 | 0 | fn nanosecond(&self) -> Option<NanoSecond> { |
296 | 0 | self.nanosecond |
297 | 0 | } |
298 | | } |
299 | | |
300 | | impl TimeZoneInput for ExtractedTimeZoneInput { |
301 | 0 | fn gmt_offset(&self) -> Option<GmtOffset> { |
302 | 0 | self.gmt_offset |
303 | 0 | } |
304 | 0 | fn time_zone_id(&self) -> Option<TimeZoneBcp47Id> { |
305 | 0 | self.time_zone_id |
306 | 0 | } |
307 | 0 | fn metazone_id(&self) -> Option<MetazoneId> { |
308 | 0 | self.metazone_id |
309 | 0 | } |
310 | 0 | fn zone_variant(&self) -> Option<ZoneVariant> { |
311 | 0 | self.zone_variant |
312 | 0 | } |
313 | | } |
314 | | |
315 | | pub(crate) enum ExtractedDateTimeInputWeekCalculatorError { |
316 | | Missing(&'static str), |
317 | | } |
318 | | |
319 | | impl ExtractedDateTimeInput { |
320 | 0 | pub(crate) fn week_of_month( |
321 | 0 | &self, |
322 | 0 | calculator: &WeekCalculator, |
323 | 0 | ) -> Result<WeekOfMonth, ExtractedDateTimeInputWeekCalculatorError> { |
324 | 0 | let day_of_month = |
325 | 0 | self.day_of_month() |
326 | 0 | .ok_or(ExtractedDateTimeInputWeekCalculatorError::Missing( |
327 | 0 | "day_of_month", |
328 | 0 | ))?; |
329 | 0 | let iso_weekday = |
330 | 0 | self.iso_weekday() |
331 | 0 | .ok_or(ExtractedDateTimeInputWeekCalculatorError::Missing( |
332 | 0 | "iso_weekday", |
333 | 0 | ))?; |
334 | 0 | Ok(calculator.week_of_month(day_of_month, iso_weekday)) |
335 | 0 | } |
336 | | |
337 | 0 | pub(crate) fn week_of_year( |
338 | 0 | &self, |
339 | 0 | calculator: &WeekCalculator, |
340 | 0 | ) -> Result<(FormattableYear, WeekOfYear), ExtractedDateTimeInputWeekCalculatorError> { |
341 | 0 | let day_of_year_info = |
342 | 0 | self.day_of_year_info() |
343 | 0 | .ok_or(ExtractedDateTimeInputWeekCalculatorError::Missing( |
344 | 0 | "day_of_year_info", |
345 | 0 | ))?; |
346 | 0 | let iso_weekday = |
347 | 0 | self.iso_weekday() |
348 | 0 | .ok_or(ExtractedDateTimeInputWeekCalculatorError::Missing( |
349 | 0 | "iso_weekday", |
350 | 0 | ))?; |
351 | | // We don't have any calendars with < 14 days per year, and it's unlikely we'll add one |
352 | 0 | debug_assert!(day_of_year_info.days_in_year >= icu_calendar::week::MIN_UNIT_DAYS); |
353 | 0 | debug_assert!(day_of_year_info.days_in_prev_year >= icu_calendar::week::MIN_UNIT_DAYS); |
354 | | #[allow(clippy::unwrap_used)] |
355 | 0 | let week_of = calculator |
356 | 0 | .week_of_year(day_of_year_info, iso_weekday) |
357 | 0 | .unwrap(); |
358 | 0 | let year = match week_of.unit { |
359 | 0 | RelativeUnit::Previous => day_of_year_info.prev_year, |
360 | 0 | RelativeUnit::Current => self |
361 | 0 | .year() |
362 | 0 | .ok_or(ExtractedDateTimeInputWeekCalculatorError::Missing("year"))?, |
363 | 0 | RelativeUnit::Next => day_of_year_info.next_year, |
364 | | }; |
365 | 0 | Ok((year, WeekOfYear(week_of.week as u32))) |
366 | 0 | } |
367 | | } |
368 | | |
369 | | impl<C: Calendar, A: AsCalendar<Calendar = C>> DateInput for Date<A> { |
370 | | type Calendar = C; |
371 | | /// Gets the era and year input. |
372 | 0 | fn year(&self) -> Option<FormattableYear> { |
373 | 0 | Some(self.year()) |
374 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::year |
375 | | |
376 | | /// Gets the month input. |
377 | 0 | fn month(&self) -> Option<FormattableMonth> { |
378 | 0 | Some(self.month()) |
379 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::month |
380 | | |
381 | | /// Gets the day input. |
382 | 0 | fn day_of_month(&self) -> Option<DayOfMonth> { |
383 | 0 | Some(self.day_of_month()) |
384 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::day_of_month |
385 | | |
386 | | /// Gets the weekday input. |
387 | 0 | fn iso_weekday(&self) -> Option<IsoWeekday> { |
388 | 0 | Some(self.day_of_week()) |
389 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::iso_weekday |
390 | | |
391 | | /// Gets information on the position of the day within the year. |
392 | 0 | fn day_of_year_info(&self) -> Option<DayOfYearInfo> { |
393 | 0 | Some(self.day_of_year_info()) |
394 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::day_of_year_info |
395 | | |
396 | 0 | fn any_calendar_kind(&self) -> Option<AnyCalendarKind> { |
397 | 0 | self.calendar().any_calendar_kind() |
398 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::any_calendar_kind |
399 | | |
400 | 0 | fn to_iso(&self) -> Date<Iso> { |
401 | 0 | Date::to_iso(self) |
402 | 0 | } Unexecuted instantiation: <icu_calendar::date::Date<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::to_iso Unexecuted instantiation: <icu_calendar::date::Date<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::to_iso Unexecuted instantiation: <icu_calendar::date::Date<_> as icu_datetime::input::DateInput>::to_iso |
403 | | } |
404 | | |
405 | | impl<C: Calendar, A: AsCalendar<Calendar = C>> DateInput for DateTime<A> { |
406 | | type Calendar = C; |
407 | | /// Gets the era and year input. |
408 | 0 | fn year(&self) -> Option<FormattableYear> { |
409 | 0 | Some(self.date.year()) |
410 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::year Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::year |
411 | | |
412 | | /// Gets the month input. |
413 | 0 | fn month(&self) -> Option<FormattableMonth> { |
414 | 0 | Some(self.date.month()) |
415 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::month Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::month |
416 | | |
417 | | /// Gets the day input. |
418 | 0 | fn day_of_month(&self) -> Option<DayOfMonth> { |
419 | 0 | Some(self.date.day_of_month()) |
420 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::day_of_month Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::day_of_month |
421 | | |
422 | | /// Gets the weekday input. |
423 | 0 | fn iso_weekday(&self) -> Option<IsoWeekday> { |
424 | 0 | Some(self.date.day_of_week()) |
425 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::iso_weekday Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::iso_weekday |
426 | | |
427 | | /// Gets information on the position of the day within the year. |
428 | 0 | fn day_of_year_info(&self) -> Option<DayOfYearInfo> { |
429 | 0 | Some(self.date.day_of_year_info()) |
430 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::day_of_year_info Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::day_of_year_info |
431 | | |
432 | 0 | fn any_calendar_kind(&self) -> Option<AnyCalendarKind> { |
433 | 0 | self.date.calendar().any_calendar_kind() |
434 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::DateInput>::any_calendar_kind Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::any_calendar_kind |
435 | 0 | fn to_iso(&self) -> Date<Iso> { |
436 | 0 | Date::to_iso(&self.date) |
437 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::DateInput>::to_iso Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::DateInput>::to_iso Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::DateInput>::to_iso |
438 | | } |
439 | | |
440 | | impl<A: AsCalendar> IsoTimeInput for DateTime<A> { |
441 | | /// Gets the hour input. |
442 | 0 | fn hour(&self) -> Option<IsoHour> { |
443 | 0 | Some(self.time.hour) |
444 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::hour Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::hour Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::IsoTimeInput>::hour Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::iso::Iso> as icu_datetime::input::IsoTimeInput>::hour Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::IsoTimeInput>::hour Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::IsoTimeInput>::hour |
445 | | |
446 | | /// Gets the minute input. |
447 | 0 | fn minute(&self) -> Option<IsoMinute> { |
448 | 0 | Some(self.time.minute) |
449 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::minute Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::minute Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::IsoTimeInput>::minute Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::iso::Iso> as icu_datetime::input::IsoTimeInput>::minute Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::IsoTimeInput>::minute Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::IsoTimeInput>::minute |
450 | | |
451 | | /// Gets the second input. |
452 | 0 | fn second(&self) -> Option<IsoSecond> { |
453 | 0 | Some(self.time.second) |
454 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::second Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::second Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::IsoTimeInput>::second Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::iso::Iso> as icu_datetime::input::IsoTimeInput>::second Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::IsoTimeInput>::second Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::IsoTimeInput>::second |
455 | | |
456 | | /// Gets the fractional second input. |
457 | 0 | fn nanosecond(&self) -> Option<NanoSecond> { |
458 | 0 | Some(self.time.nanosecond) |
459 | 0 | } Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::date::Ref<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::nanosecond Unexecuted instantiation: <icu_calendar::datetime::DateTime<alloc::sync::Arc<icu_calendar::any_calendar::AnyCalendar>> as icu_datetime::input::IsoTimeInput>::nanosecond Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::any_calendar::AnyCalendar> as icu_datetime::input::IsoTimeInput>::nanosecond Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::iso::Iso> as icu_datetime::input::IsoTimeInput>::nanosecond Unexecuted instantiation: <icu_calendar::datetime::DateTime<icu_calendar::gregorian::Gregorian> as icu_datetime::input::IsoTimeInput>::nanosecond Unexecuted instantiation: <icu_calendar::datetime::DateTime<_> as icu_datetime::input::IsoTimeInput>::nanosecond |
460 | | } |
461 | | |
462 | | impl TimeZoneInput for CustomTimeZone { |
463 | 0 | fn gmt_offset(&self) -> Option<GmtOffset> { |
464 | 0 | self.gmt_offset |
465 | 0 | } |
466 | | |
467 | 0 | fn time_zone_id(&self) -> Option<TimeZoneBcp47Id> { |
468 | 0 | self.time_zone_id |
469 | 0 | } |
470 | | |
471 | 0 | fn metazone_id(&self) -> Option<MetazoneId> { |
472 | 0 | self.metazone_id |
473 | 0 | } |
474 | | |
475 | 0 | fn zone_variant(&self) -> Option<ZoneVariant> { |
476 | 0 | self.zone_variant |
477 | 0 | } |
478 | | } |
479 | | |
480 | | impl IsoTimeInput for Time { |
481 | 0 | fn hour(&self) -> Option<IsoHour> { |
482 | 0 | Some(self.hour) |
483 | 0 | } |
484 | 0 | fn minute(&self) -> Option<IsoMinute> { |
485 | 0 | Some(self.minute) |
486 | 0 | } |
487 | 0 | fn second(&self) -> Option<IsoSecond> { |
488 | 0 | Some(self.second) |
489 | 0 | } |
490 | 0 | fn nanosecond(&self) -> Option<NanoSecond> { |
491 | 0 | Some(self.nanosecond) |
492 | 0 | } |
493 | | } |