1#[rustfmt::skip]
8#[diplomat::bridge]
9#[diplomat::abi_rename = "icu4x_{0}_mv1"]
10#[diplomat::attr(auto, namespace = "icu4x")]
11pub mod ffi {
12 use alloc::boxed::Box;
13 use icu_calendar::Gregorian;
14 use writeable::TryWriteable;
15
16 #[allow(unused_imports)]
17 use crate::{
18 date_formatter::ffi::{DateFormatter, DateFormatterGregorian},
19 date_time_formatter::ffi::{DateTimeFormatter, DateTimeFormatterGregorian},
20 date::ffi::IsoDate,
21 datetime_helpers,
22 datetime_helpers::map_or_default,
23 datetime_options::ffi::{DateTimeAlignment, DateTimeLength, TimePrecision},
24 errors::ffi::DateTimeFormatterLoadError,
25 errors::ffi::DateTimeWriteError,
26 locale_core::ffi::Locale,
27 time_formatter::ffi::TimeFormatter,
28 time::ffi::Time,
29 timezone::ffi::TimeZoneInfo,
30 };
31
32 #[cfg(feature = "buffer_provider")]
33 use crate::provider::ffi::DataProvider;
34
35 #[diplomat::opaque]
36 #[diplomat::rust_link(icu::datetime::DateTimeFormatter, Typedef)]
37 pub struct ZonedDateFormatter(
38 pub icu_datetime::DateTimeFormatter<
39 icu_datetime::fieldsets::enums::ZonedDateFieldSet
40 >,
41 );
42
43 impl ZonedDateFormatter {
44 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long")]
45 #[cfg(feature = "compiled_data")]
46 pub fn create_specific_long(
47 locale: &Locale,
48 formatter: &DateFormatter,
49 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
50 let zone = icu_datetime::fieldsets::zone::SpecificLong;
51 datetime_helpers::date_formatter_with_zone(
52 &formatter.0,
53 locale,
54 zone,
55 |names| {
56 names
57 .as_mut()
58 .include_time_zone_specific_long_names_with_fallback(
59 )?;
60 Ok(())
61 },
62 |names, field_set| names.try_into_formatter(
63 field_set
64 ),
65 )
66 }
67
68 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long_with_provider")]
69 #[cfg(feature = "buffer_provider")]
70 pub fn create_specific_long_with_provider(
71 provider: &DataProvider,
72 locale: &Locale,
73 formatter: &DateFormatter,
74 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
75 let provider = provider.get()?;
76 let zone = icu_datetime::fieldsets::zone::SpecificLong;
77 datetime_helpers::date_formatter_with_zone(
78 &formatter.0,
79 locale,
80 zone,
81 |names| {
82 use icu_provider::buf::AsDeserializingBufferProvider;
83 let provider = provider.as_deserializing();
84 names
85 .as_mut()
86 .load_time_zone_specific_long_names_with_fallback(
87 &provider
88 )?;
89 Ok(())
90 },
91 |names, field_set| names.try_into_formatter_with_buffer_provider(
92 &provider,
93 field_set
94 ),
95 )
96 }
97
98 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short")]
99 #[cfg(feature = "compiled_data")]
100 pub fn create_specific_short(
101 locale: &Locale,
102 formatter: &DateFormatter,
103 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
104 let zone = icu_datetime::fieldsets::zone::SpecificShort;
105 datetime_helpers::date_formatter_with_zone(
106 &formatter.0,
107 locale,
108 zone,
109 |names| {
110 names
111 .as_mut()
112 .include_time_zone_specific_short_names_with_fallback(
113 )?;
114 Ok(())
115 },
116 |names, field_set| names.try_into_formatter(
117 field_set
118 ),
119 )
120 }
121
122 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short_with_provider")]
123 #[cfg(feature = "buffer_provider")]
124 pub fn create_specific_short_with_provider(
125 provider: &DataProvider,
126 locale: &Locale,
127 formatter: &DateFormatter,
128 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
129 let provider = provider.get()?;
130 let zone = icu_datetime::fieldsets::zone::SpecificShort;
131 datetime_helpers::date_formatter_with_zone(
132 &formatter.0,
133 locale,
134 zone,
135 |names| {
136 use icu_provider::buf::AsDeserializingBufferProvider;
137 let provider = provider.as_deserializing();
138 names
139 .as_mut()
140 .load_time_zone_specific_short_names_with_fallback(
141 &provider
142 )?;
143 Ok(())
144 },
145 |names, field_set| names.try_into_formatter_with_buffer_provider(
146 &provider,
147 field_set
148 ),
149 )
150 }
151
152 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long")]
153 #[cfg(feature = "compiled_data")]
154 pub fn create_localized_offset_long(
155 locale: &Locale,
156 formatter: &DateFormatter,
157 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
158 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
159 datetime_helpers::date_formatter_with_zone(
160 &formatter.0,
161 locale,
162 zone,
163 |names| {
164 names
165 .as_mut()
166 .include_time_zone_localized_offset_names_with_fallback(
167 )?;
168 Ok(())
169 },
170 |names, field_set| names.try_into_formatter(
171 field_set
172 ),
173 )
174 }
175
176 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long_with_provider")]
177 #[cfg(feature = "buffer_provider")]
178 pub fn create_localized_offset_long_with_provider(
179 provider: &DataProvider,
180 locale: &Locale,
181 formatter: &DateFormatter,
182 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
183 let provider = provider.get()?;
184 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
185 datetime_helpers::date_formatter_with_zone(
186 &formatter.0,
187 locale,
188 zone,
189 |names| {
190 use icu_provider::buf::AsDeserializingBufferProvider;
191 let provider = provider.as_deserializing();
192 names
193 .as_mut()
194 .load_time_zone_localized_offset_names_with_fallback(
195 &provider
196 )?;
197 Ok(())
198 },
199 |names, field_set| names.try_into_formatter_with_buffer_provider(
200 &provider,
201 field_set
202 ),
203 )
204 }
205
206 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short")]
207 #[cfg(feature = "compiled_data")]
208 pub fn create_localized_offset_short(
209 locale: &Locale,
210 formatter: &DateFormatter,
211 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
212 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
213 datetime_helpers::date_formatter_with_zone(
214 &formatter.0,
215 locale,
216 zone,
217 |names| {
218 names
219 .as_mut()
220 .include_time_zone_localized_offset_names_with_fallback(
221 )?;
222 Ok(())
223 },
224 |names, field_set| names.try_into_formatter(
225 field_set
226 ),
227 )
228 }
229
230 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short_with_provider")]
231 #[cfg(feature = "buffer_provider")]
232 pub fn create_localized_offset_short_with_provider(
233 provider: &DataProvider,
234 locale: &Locale,
235 formatter: &DateFormatter,
236 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
237 let provider = provider.get()?;
238 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
239 datetime_helpers::date_formatter_with_zone(
240 &formatter.0,
241 locale,
242 zone,
243 |names| {
244 use icu_provider::buf::AsDeserializingBufferProvider;
245 let provider = provider.as_deserializing();
246 names
247 .as_mut()
248 .load_time_zone_localized_offset_names_with_fallback(
249 &provider
250 )?;
251 Ok(())
252 },
253 |names, field_set| names.try_into_formatter_with_buffer_provider(
254 &provider,
255 field_set
256 ),
257 )
258 }
259
260 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long")]
261 #[cfg(feature = "compiled_data")]
262 pub fn create_generic_long(
263 locale: &Locale,
264 formatter: &DateFormatter,
265 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
266 let zone = icu_datetime::fieldsets::zone::GenericLong;
267 datetime_helpers::date_formatter_with_zone(
268 &formatter.0,
269 locale,
270 zone,
271 |names| {
272 names
273 .as_mut()
274 .include_time_zone_generic_long_names_with_fallback(
275 )?;
276 Ok(())
277 },
278 |names, field_set| names.try_into_formatter(
279 field_set
280 ),
281 )
282 }
283
284 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long_with_provider")]
285 #[cfg(feature = "buffer_provider")]
286 pub fn create_generic_long_with_provider(
287 provider: &DataProvider,
288 locale: &Locale,
289 formatter: &DateFormatter,
290 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
291 let provider = provider.get()?;
292 let zone = icu_datetime::fieldsets::zone::GenericLong;
293 datetime_helpers::date_formatter_with_zone(
294 &formatter.0,
295 locale,
296 zone,
297 |names| {
298 use icu_provider::buf::AsDeserializingBufferProvider;
299 let provider = provider.as_deserializing();
300 names
301 .as_mut()
302 .load_time_zone_generic_long_names_with_fallback(
303 &provider
304 )?;
305 Ok(())
306 },
307 |names, field_set| names.try_into_formatter_with_buffer_provider(
308 &provider,
309 field_set
310 ),
311 )
312 }
313
314 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short")]
315 #[diplomat::demo(default_constructor)]
316 #[cfg(feature = "compiled_data")]
317 pub fn create_generic_short(
318 locale: &Locale,
319 formatter: &DateFormatter,
320 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
321 let zone = icu_datetime::fieldsets::zone::GenericShort;
322 datetime_helpers::date_formatter_with_zone(
323 &formatter.0,
324 locale,
325 zone,
326 |names| {
327 names
328 .as_mut()
329 .include_time_zone_generic_short_names_with_fallback(
330 )?;
331 Ok(())
332 },
333 |names, field_set| names.try_into_formatter(
334 field_set
335 ),
336 )
337 }
338
339 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short_with_provider")]
340 #[cfg(feature = "buffer_provider")]
341 pub fn create_generic_short_with_provider(
342 provider: &DataProvider,
343 locale: &Locale,
344 formatter: &DateFormatter,
345 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
346 let provider = provider.get()?;
347 let zone = icu_datetime::fieldsets::zone::GenericShort;
348 datetime_helpers::date_formatter_with_zone(
349 &formatter.0,
350 locale,
351 zone,
352 |names| {
353 use icu_provider::buf::AsDeserializingBufferProvider;
354 let provider = provider.as_deserializing();
355 names
356 .as_mut()
357 .load_time_zone_generic_short_names_with_fallback(
358 &provider
359 )?;
360 Ok(())
361 },
362 |names, field_set| names.try_into_formatter_with_buffer_provider(
363 &provider,
364 field_set
365 ),
366 )
367 }
368
369 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location")]
370 #[cfg(feature = "compiled_data")]
371 pub fn create_location(
372 locale: &Locale,
373 formatter: &DateFormatter,
374 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
375 let zone = icu_datetime::fieldsets::zone::Location;
376 datetime_helpers::date_formatter_with_zone(
377 &formatter.0,
378 locale,
379 zone,
380 |names| {
381 names
382 .as_mut()
383 .include_time_zone_location_names(
384 )?;
385 Ok(())
386 },
387 |names, field_set| names.try_into_formatter(
388 field_set
389 ),
390 )
391 }
392
393 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location_with_provider")]
394 #[cfg(feature = "buffer_provider")]
395 pub fn create_location_with_provider(
396 provider: &DataProvider,
397 locale: &Locale,
398 formatter: &DateFormatter,
399 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
400 let provider = provider.get()?;
401 let zone = icu_datetime::fieldsets::zone::Location;
402 datetime_helpers::date_formatter_with_zone(
403 &formatter.0,
404 locale,
405 zone,
406 |names| {
407 use icu_provider::buf::AsDeserializingBufferProvider;
408 let provider = provider.as_deserializing();
409 names
410 .as_mut()
411 .load_time_zone_location_names(
412 &provider
413 )?;
414 Ok(())
415 },
416 |names, field_set| names.try_into_formatter_with_buffer_provider(
417 &provider,
418 field_set
419 ),
420 )
421 }
422
423 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city")]
424 #[cfg(feature = "compiled_data")]
425 pub fn create_exemplar_city(
426 locale: &Locale,
427 formatter: &DateFormatter,
428 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
429 let zone = icu_datetime::fieldsets::zone::ExemplarCity;
430 datetime_helpers::date_formatter_with_zone(
431 &formatter.0,
432 locale,
433 zone,
434 |names| {
435 names
436 .as_mut()
437 .include_time_zone_exemplar_city_names(
438 )?;
439 Ok(())
440 },
441 |names, field_set| names.try_into_formatter(
442 field_set
443 ),
444 )
445 }
446
447 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city_with_provider")]
448 #[cfg(feature = "buffer_provider")]
449 pub fn create_exemplar_city_with_provider(
450 provider: &DataProvider,
451 locale: &Locale,
452 formatter: &DateFormatter,
453 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
454 let provider = provider.get()?;
455 let zone = icu_datetime::fieldsets::zone::ExemplarCity;
456 datetime_helpers::date_formatter_with_zone(
457 &formatter.0,
458 locale,
459 zone,
460 |names| {
461 use icu_provider::buf::AsDeserializingBufferProvider;
462 let provider = provider.as_deserializing();
463 names
464 .as_mut()
465 .load_time_zone_exemplar_city_names(
466 &provider
467 )?;
468 Ok(())
469 },
470 |names, field_set| names.try_into_formatter_with_buffer_provider(
471 &provider,
472 field_set
473 ),
474 )
475 }
476
477 #[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
478 #[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
479 #[diplomat::rust_link(icu::datetime::FormattedDateTime::to_string, FnInStruct, hidden)]
480 pub fn format_iso(
481 &self,
482 date: &IsoDate,
483 zone: &TimeZoneInfo,
484 write: &mut diplomat_runtime::DiplomatWrite,
485 ) -> Result<(), DateTimeWriteError> {
486 let mut input = icu_datetime::DateTimeInputUnchecked::default();
487 let date = date.0.to_calendar(self.0.calendar());
488 input.set_date_fields(date);
489 input.set_time_zone_id(zone.time_zone_id);
490 if let Some(offset) = zone.offset {
491 input.set_time_zone_utc_offset(offset);
492 }
493 if let Some(local_time) = zone.local_time {
494 input.set_time_zone_local_time(local_time);
495 }
496 if let Some(zone_variant) = zone.zone_variant {
497 input.set_time_zone_variant(zone_variant);
498 }
499 let _infallible = self
500 .0
501 .format_unchecked(input)
502 .try_write_to(write)
503 .ok()
504 .transpose()?;
505 Ok(())
506 }
507 }
508
509
510 #[diplomat::opaque]
511 #[diplomat::rust_link(icu::datetime::FixedCalendarDateTimeFormatter, Typedef)]
512 pub struct ZonedDateFormatterGregorian(
513 pub icu_datetime::FixedCalendarDateTimeFormatter<
514 Gregorian,
515 icu_datetime::fieldsets::enums::ZonedDateFieldSet
516 >,
517 );
518
519 impl ZonedDateFormatterGregorian {
520 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long")]
521 #[cfg(feature = "compiled_data")]
522 pub fn create_specific_long(
523 locale: &Locale,
524 formatter: &DateFormatterGregorian,
525 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
526 let zone = icu_datetime::fieldsets::zone::SpecificLong;
527 datetime_helpers::date_formatter_gregorian_with_zone(
528 &formatter.0,
529 locale,
530 zone,
531 |names| {
532 names
533 .include_time_zone_specific_long_names_with_fallback(
534 )?;
535 Ok(())
536 },
537 |names, field_set| names.try_into_formatter(
538 field_set
539 ),
540 )
541 }
542
543 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long_with_provider")]
544 #[cfg(feature = "buffer_provider")]
545 pub fn create_specific_long_with_provider(
546 provider: &DataProvider,
547 locale: &Locale,
548 formatter: &DateFormatterGregorian,
549 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
550 let provider = provider.get()?;
551 let zone = icu_datetime::fieldsets::zone::SpecificLong;
552 datetime_helpers::date_formatter_gregorian_with_zone(
553 &formatter.0,
554 locale,
555 zone,
556 |names| {
557 use icu_provider::buf::AsDeserializingBufferProvider;
558 let provider = provider.as_deserializing();
559 names
560 .load_time_zone_specific_long_names_with_fallback(
561 &provider
562 )?;
563 Ok(())
564 },
565 |names, field_set| names.try_into_formatter_with_buffer_provider(
566 &provider,
567 field_set
568 ),
569 )
570 }
571
572 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short")]
573 #[cfg(feature = "compiled_data")]
574 pub fn create_specific_short(
575 locale: &Locale,
576 formatter: &DateFormatterGregorian,
577 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
578 let zone = icu_datetime::fieldsets::zone::SpecificShort;
579 datetime_helpers::date_formatter_gregorian_with_zone(
580 &formatter.0,
581 locale,
582 zone,
583 |names| {
584 names
585 .include_time_zone_specific_short_names_with_fallback(
586 )?;
587 Ok(())
588 },
589 |names, field_set| names.try_into_formatter(
590 field_set
591 ),
592 )
593 }
594
595 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short_with_provider")]
596 #[cfg(feature = "buffer_provider")]
597 pub fn create_specific_short_with_provider(
598 provider: &DataProvider,
599 locale: &Locale,
600 formatter: &DateFormatterGregorian,
601 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
602 let provider = provider.get()?;
603 let zone = icu_datetime::fieldsets::zone::SpecificShort;
604 datetime_helpers::date_formatter_gregorian_with_zone(
605 &formatter.0,
606 locale,
607 zone,
608 |names| {
609 use icu_provider::buf::AsDeserializingBufferProvider;
610 let provider = provider.as_deserializing();
611 names
612 .load_time_zone_specific_short_names_with_fallback(
613 &provider
614 )?;
615 Ok(())
616 },
617 |names, field_set| names.try_into_formatter_with_buffer_provider(
618 &provider,
619 field_set
620 ),
621 )
622 }
623
624 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long")]
625 #[cfg(feature = "compiled_data")]
626 pub fn create_localized_offset_long(
627 locale: &Locale,
628 formatter: &DateFormatterGregorian,
629 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
630 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
631 datetime_helpers::date_formatter_gregorian_with_zone(
632 &formatter.0,
633 locale,
634 zone,
635 |names| {
636 names
637 .include_time_zone_localized_offset_names_with_fallback(
638 )?;
639 Ok(())
640 },
641 |names, field_set| names.try_into_formatter(
642 field_set
643 ),
644 )
645 }
646
647 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long_with_provider")]
648 #[cfg(feature = "buffer_provider")]
649 pub fn create_localized_offset_long_with_provider(
650 provider: &DataProvider,
651 locale: &Locale,
652 formatter: &DateFormatterGregorian,
653 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
654 let provider = provider.get()?;
655 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
656 datetime_helpers::date_formatter_gregorian_with_zone(
657 &formatter.0,
658 locale,
659 zone,
660 |names| {
661 use icu_provider::buf::AsDeserializingBufferProvider;
662 let provider = provider.as_deserializing();
663 names
664 .load_time_zone_localized_offset_names_with_fallback(
665 &provider
666 )?;
667 Ok(())
668 },
669 |names, field_set| names.try_into_formatter_with_buffer_provider(
670 &provider,
671 field_set
672 ),
673 )
674 }
675
676 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short")]
677 #[cfg(feature = "compiled_data")]
678 pub fn create_localized_offset_short(
679 locale: &Locale,
680 formatter: &DateFormatterGregorian,
681 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
682 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
683 datetime_helpers::date_formatter_gregorian_with_zone(
684 &formatter.0,
685 locale,
686 zone,
687 |names| {
688 names
689 .include_time_zone_localized_offset_names_with_fallback(
690 )?;
691 Ok(())
692 },
693 |names, field_set| names.try_into_formatter(
694 field_set
695 ),
696 )
697 }
698
699 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short_with_provider")]
700 #[cfg(feature = "buffer_provider")]
701 pub fn create_localized_offset_short_with_provider(
702 provider: &DataProvider,
703 locale: &Locale,
704 formatter: &DateFormatterGregorian,
705 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
706 let provider = provider.get()?;
707 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
708 datetime_helpers::date_formatter_gregorian_with_zone(
709 &formatter.0,
710 locale,
711 zone,
712 |names| {
713 use icu_provider::buf::AsDeserializingBufferProvider;
714 let provider = provider.as_deserializing();
715 names
716 .load_time_zone_localized_offset_names_with_fallback(
717 &provider
718 )?;
719 Ok(())
720 },
721 |names, field_set| names.try_into_formatter_with_buffer_provider(
722 &provider,
723 field_set
724 ),
725 )
726 }
727
728 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long")]
729 #[cfg(feature = "compiled_data")]
730 pub fn create_generic_long(
731 locale: &Locale,
732 formatter: &DateFormatterGregorian,
733 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
734 let zone = icu_datetime::fieldsets::zone::GenericLong;
735 datetime_helpers::date_formatter_gregorian_with_zone(
736 &formatter.0,
737 locale,
738 zone,
739 |names| {
740 names
741 .include_time_zone_generic_long_names_with_fallback(
742 )?;
743 Ok(())
744 },
745 |names, field_set| names.try_into_formatter(
746 field_set
747 ),
748 )
749 }
750
751 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long_with_provider")]
752 #[cfg(feature = "buffer_provider")]
753 pub fn create_generic_long_with_provider(
754 provider: &DataProvider,
755 locale: &Locale,
756 formatter: &DateFormatterGregorian,
757 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
758 let provider = provider.get()?;
759 let zone = icu_datetime::fieldsets::zone::GenericLong;
760 datetime_helpers::date_formatter_gregorian_with_zone(
761 &formatter.0,
762 locale,
763 zone,
764 |names| {
765 use icu_provider::buf::AsDeserializingBufferProvider;
766 let provider = provider.as_deserializing();
767 names
768 .load_time_zone_generic_long_names_with_fallback(
769 &provider
770 )?;
771 Ok(())
772 },
773 |names, field_set| names.try_into_formatter_with_buffer_provider(
774 &provider,
775 field_set
776 ),
777 )
778 }
779
780 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short")]
781 #[diplomat::demo(default_constructor)]
782 #[cfg(feature = "compiled_data")]
783 pub fn create_generic_short(
784 locale: &Locale,
785 formatter: &DateFormatterGregorian,
786 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
787 let zone = icu_datetime::fieldsets::zone::GenericShort;
788 datetime_helpers::date_formatter_gregorian_with_zone(
789 &formatter.0,
790 locale,
791 zone,
792 |names| {
793 names
794 .include_time_zone_generic_short_names_with_fallback(
795 )?;
796 Ok(())
797 },
798 |names, field_set| names.try_into_formatter(
799 field_set
800 ),
801 )
802 }
803
804 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short_with_provider")]
805 #[cfg(feature = "buffer_provider")]
806 pub fn create_generic_short_with_provider(
807 provider: &DataProvider,
808 locale: &Locale,
809 formatter: &DateFormatterGregorian,
810 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
811 let provider = provider.get()?;
812 let zone = icu_datetime::fieldsets::zone::GenericShort;
813 datetime_helpers::date_formatter_gregorian_with_zone(
814 &formatter.0,
815 locale,
816 zone,
817 |names| {
818 use icu_provider::buf::AsDeserializingBufferProvider;
819 let provider = provider.as_deserializing();
820 names
821 .load_time_zone_generic_short_names_with_fallback(
822 &provider
823 )?;
824 Ok(())
825 },
826 |names, field_set| names.try_into_formatter_with_buffer_provider(
827 &provider,
828 field_set
829 ),
830 )
831 }
832
833 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location")]
834 #[cfg(feature = "compiled_data")]
835 pub fn create_location(
836 locale: &Locale,
837 formatter: &DateFormatterGregorian,
838 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
839 let zone = icu_datetime::fieldsets::zone::Location;
840 datetime_helpers::date_formatter_gregorian_with_zone(
841 &formatter.0,
842 locale,
843 zone,
844 |names| {
845 names
846 .include_time_zone_location_names(
847 )?;
848 Ok(())
849 },
850 |names, field_set| names.try_into_formatter(
851 field_set
852 ),
853 )
854 }
855
856 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location_with_provider")]
857 #[cfg(feature = "buffer_provider")]
858 pub fn create_location_with_provider(
859 provider: &DataProvider,
860 locale: &Locale,
861 formatter: &DateFormatterGregorian,
862 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
863 let provider = provider.get()?;
864 let zone = icu_datetime::fieldsets::zone::Location;
865 datetime_helpers::date_formatter_gregorian_with_zone(
866 &formatter.0,
867 locale,
868 zone,
869 |names| {
870 use icu_provider::buf::AsDeserializingBufferProvider;
871 let provider = provider.as_deserializing();
872 names
873 .load_time_zone_location_names(
874 &provider
875 )?;
876 Ok(())
877 },
878 |names, field_set| names.try_into_formatter_with_buffer_provider(
879 &provider,
880 field_set
881 ),
882 )
883 }
884
885 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city")]
886 #[cfg(feature = "compiled_data")]
887 pub fn create_exemplar_city(
888 locale: &Locale,
889 formatter: &DateFormatterGregorian,
890 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
891 let zone = icu_datetime::fieldsets::zone::ExemplarCity;
892 datetime_helpers::date_formatter_gregorian_with_zone(
893 &formatter.0,
894 locale,
895 zone,
896 |names| {
897 names
898 .include_time_zone_exemplar_city_names(
899 )?;
900 Ok(())
901 },
902 |names, field_set| names.try_into_formatter(
903 field_set
904 ),
905 )
906 }
907
908 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city_with_provider")]
909 #[cfg(feature = "buffer_provider")]
910 pub fn create_exemplar_city_with_provider(
911 provider: &DataProvider,
912 locale: &Locale,
913 formatter: &DateFormatterGregorian,
914 ) -> Result<Box<Self>, DateTimeFormatterLoadError> {
915 let provider = provider.get()?;
916 let zone = icu_datetime::fieldsets::zone::ExemplarCity;
917 datetime_helpers::date_formatter_gregorian_with_zone(
918 &formatter.0,
919 locale,
920 zone,
921 |names| {
922 use icu_provider::buf::AsDeserializingBufferProvider;
923 let provider = provider.as_deserializing();
924 names
925 .load_time_zone_exemplar_city_names(
926 &provider
927 )?;
928 Ok(())
929 },
930 |names, field_set| names.try_into_formatter_with_buffer_provider(
931 &provider,
932 field_set
933 ),
934 )
935 }
936
937 #[diplomat::rust_link(icu::datetime::FixedCalendarDateTimeFormatter::format, FnInStruct)]
938 #[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
939 #[diplomat::rust_link(icu::datetime::FormattedDateTime::to_string, FnInStruct, hidden)]
940 pub fn format_iso(
941 &self,
942 date: &IsoDate,
943 zone: &TimeZoneInfo,
944 write: &mut diplomat_runtime::DiplomatWrite,
945 ) -> Result<(), DateTimeWriteError> {
946 let mut input = icu_datetime::DateTimeInputUnchecked::default();
947 let date = date.0.to_calendar(Gregorian);
948 input.set_date_fields(date);
949 input.set_time_zone_id(zone.time_zone_id);
950 if let Some(offset) = zone.offset {
951 input.set_time_zone_utc_offset(offset);
952 }
953 if let Some(local_time) = zone.local_time {
954 input.set_time_zone_local_time(local_time);
955 }
956 if let Some(zone_variant) = zone.zone_variant {
957 input.set_time_zone_variant(zone_variant);
958 }
959 let _infallible = self
960 .0
961 .format_unchecked(input)
962 .try_write_to(write)
963 .ok()
964 .transpose()?;
965 Ok(())
966 }
967 }
968
969}