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

zbraniecki / icu4x / 9014530096

08 May 2024 07:27PM UTC coverage: 76.402% (+0.2%) from 76.234%
9014530096

push

github

web-flow
Add missing std pointer-like impls for DataProvider, DynamicDataProvider (#4880)

0 of 3 new or added lines in 1 file covered. (0.0%)

3218 existing lines in 167 files now uncovered.

53328 of 69799 relevant lines covered (76.4%)

504343.42 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
#[cfg(doc)]
21
use crate::ZonedDateTimeFormatter;
22

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

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

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

48
        debug_assert!(r.is_ok(), "{r:?}");
667✔
49
        Ok(())
667✔
50
    }
667✔
51

52
    // TODO(#489): Implement writeable_length_hint
53
}
54

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

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