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

zbraniecki / icu4x / 9207498870

23 May 2024 07:11AM UTC coverage: 76.113% (-0.3%) from 76.402%
9207498870

push

github

web-flow
Add to `IsoDurationParser` documentation in `ixdtf` (#4916)

53397 of 70155 relevant lines covered (76.11%)

514353.71 hits per line

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

88.89
/components/datetime/src/format/zoned_datetime.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
//! A collection of code for formatting DateTimes with time zones.
6

7
use crate::fields::{Field, FieldSymbol};
8
use crate::format::datetime::{self, DateTimeWriteError};
9
use crate::input::{ExtractedDateTimeInput, ExtractedTimeZoneInput};
10
use crate::pattern::runtime::PatternBorrowed;
11
use crate::pattern::PatternItem;
12
use crate::provider::date_time::{DateSymbols, TimeSymbols};
13
use crate::time_zone::TimeZoneFormatter;
14
use crate::{FormattedDateTime, FormattedTimeZone};
15
use core::fmt;
16
use icu_calendar::week::WeekCalculator;
17
use icu_decimal::FixedDecimalFormatter;
18
use writeable::Writeable;
19

20
/// [`FormattedTimeZone`] is a intermediate structure which can be retrieved
21
/// as an output from [`ZonedDateTimeFormatter`](super::super::ZonedDateTimeFormatter).
22
#[derive(Debug, Copy, Clone)]
×
23
pub struct FormattedZonedDateTime<'l> {
24
    pub(crate) formatted_datetime: FormattedDateTime<'l>,
×
25
    pub(crate) time_zone_format: &'l TimeZoneFormatter,
×
26
    pub(crate) time_zone: ExtractedTimeZoneInput,
×
27
}
28

29
impl<'l> Writeable for FormattedZonedDateTime<'l> {
30
    fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
667✔
31
        let (pattern, mut r) = self.formatted_datetime.select_pattern_lossy();
667✔
32

33
        r = r.and(try_write_pattern(
1,334✔
34
            pattern.as_borrowed(),
667✔
35
            &self.formatted_datetime.datetime,
667✔
36
            self.formatted_datetime.date_symbols,
667✔
37
            self.formatted_datetime.time_symbols,
667✔
38
            self.formatted_datetime.week_data,
667✔
39
            Some(self.formatted_datetime.fixed_decimal_format),
667✔
40
            &self.time_zone,
667✔
41
            self.time_zone_format,
667✔
42
            &mut writeable::adapters::CoreWriteAsPartsWrite(sink),
667✔
43
        )?);
44

45
        debug_assert!(r.is_ok(), "{r:?}");
667✔
46
        Ok(())
667✔
47
    }
667✔
48

49
    // TODO(#489): Implement writeable_length_hint
50
}
51

52
impl<'l> fmt::Display for FormattedZonedDateTime<'l> {
53
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133✔
54
        self.write_to(f)
133✔
55
    }
133✔
56
}
57

58
#[allow(clippy::too_many_arguments)]
59
fn try_write_pattern<'data, W, DS, TS>(
667✔
60
    pattern: PatternBorrowed<'data>,
61
    datetime: &ExtractedDateTimeInput,
62
    date_symbols: Option<&DS>,
63
    time_symbols: Option<&TS>,
64
    week_data: Option<&'data WeekCalculator>,
65
    fixed_decimal_format: Option<&FixedDecimalFormatter>,
66
    time_zone: &ExtractedTimeZoneInput,
67
    time_zone_format: &TimeZoneFormatter,
68
    w: &mut W,
69
) -> Result<Result<(), DateTimeWriteError>, fmt::Error>
70
where
71
    W: writeable::PartsWrite + ?Sized,
72
    DS: DateSymbols<'data>,
73
    TS: TimeSymbols,
74
{
75
    let mut r = Ok(());
667✔
76
    let mut iter = pattern.items.iter().peekable();
667✔
77
    while let Some(item) = iter.next() {
3,886✔
78
        match item {
3,219✔
79
            PatternItem::Literal(ch) => w.write_char(ch)?,
1,543✔
80
            PatternItem::Field(Field {
81
                symbol: FieldSymbol::TimeZone(..),
82
                ..
83
            }) => FormattedTimeZone {
652✔
84
                time_zone_format,
85
                time_zone,
86
            }
87
            .write_to(w)?,
88
            PatternItem::Field(field) => {
1,024✔
89
                r = r.and(datetime::try_write_field(
2,048✔
90
                    field,
1,024✔
91
                    &mut iter,
92
                    pattern.metadata,
1,024✔
93
                    datetime,
94
                    date_symbols,
95
                    time_symbols,
96
                    week_data,
97
                    fixed_decimal_format,
98
                    w,
99
                )?);
100
            }
1,024✔
101
        }
102
    }
103
    Ok(r)
667✔
104
}
667✔
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

© 2025 Coveralls, Inc