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

zbraniecki / icu4x / 7319540133

25 Dec 2023 03:39AM UTC coverage: 72.884% (-0.1%) from 73.022%
7319540133

push

github

web-flow
Make ZeroVec have a niche via NonNull (#4491)

7 of 7 new or added lines in 2 files covered. (100.0%)

2721 existing lines in 221 files now uncovered.

46318 of 63550 relevant lines covered (72.88%)

272438.55 hits per line

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

92.86
/components/datetime/src/pattern/mod.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
mod common;
6
mod error;
7
pub mod hour_cycle;
8
mod item;
9
pub mod reference;
10
pub mod runtime;
11

12
use crate::fields;
13
pub use error::PatternError;
14
pub use hour_cycle::CoarseHourCycle;
15
use icu_provider::prelude::*;
16
pub use item::{GenericPatternItem, PatternItem};
17

18
/// The granularity of time represented in a pattern item.
19
/// Ordered from least granular to most granular for comparison.
20
#[derive(
21
    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, yoke::Yokeable, zerofrom::ZeroFrom,
4,299✔
22
)]
23
#[cfg_attr(
24
    feature = "datagen",
25
    derive(serde::Serialize, databake::Bake),
9✔
26
    databake(path = icu_datetime::pattern),
27
)]
28
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
126✔
29
#[non_exhaustive]
30
pub enum TimeGranularity {
31✔
31
    None,
32
    Hours,
33
    Minutes,
34
    Seconds,
35
    Nanoseconds,
36
}
37

38
impl Default for TimeGranularity {
39
    fn default() -> Self {
14✔
40
        Self::None
14✔
41
    }
14✔
42
}
43

44
impl TimeGranularity {
45
    /// Returns [`true`] if the most granular time being displayed will align with
46
    /// the top of the hour, otherwise returns [`false`].
47
    /// e.g. `12:00:00` is at the top of the hour for any display granularity.
48
    /// e.g. `12:00:05` is only at the top of the hour if the seconds are not displayed.
49
    pub fn is_top_of_hour(self, minute: u8, second: u8, nanosecond: u32) -> bool {
830✔
50
        match self {
830✔
51
            Self::None | Self::Hours => true,
429✔
52
            Self::Minutes => minute == 0,
192✔
53
            Self::Seconds => minute + second == 0,
209✔
54
            Self::Nanoseconds => minute as u32 + second as u32 + nanosecond == 0,
×
55
        }
56
    }
830✔
57

58
    #[inline]
59
    pub(crate) fn from_ordinal(ordinal: u8) -> TimeGranularity {
585✔
60
        use TimeGranularity::*;
61
        match ordinal {
585✔
62
            1 => Hours,
51✔
63
            2 => Minutes,
141✔
64
            3 => Seconds,
142✔
UNCOV
65
            4 => Nanoseconds,
×
66
            _ => None,
251✔
67
        }
68
    }
585✔
69

70
    #[inline]
71
    pub(crate) const fn ordinal(self) -> u8 {
1,122✔
72
        use TimeGranularity::*;
73
        match self {
1,122✔
74
            None => 0,
728✔
75
            Hours => 1,
52✔
76
            Minutes => 2,
119✔
77
            Seconds => 3,
206✔
78
            Nanoseconds => 4,
17✔
79
        }
80
    }
1,122✔
81
}
82

83
impl From<&PatternItem> for TimeGranularity {
84
    /// Retrieves the granularity of time represented by a [`PatternItem`].
85
    /// If the [`PatternItem`] is not time-related, returns [`None`].
86
    fn from(item: &PatternItem) -> Self {
5,471✔
87
        match item {
5,471✔
88
            PatternItem::Field(field) => match field.symbol {
2,932✔
89
                fields::FieldSymbol::Hour(_) => Self::Hours,
376✔
90
                fields::FieldSymbol::Minute => Self::Minutes,
353✔
91
                fields::FieldSymbol::Second(s) => match s {
251✔
92
                    fields::Second::FractionalSecond => Self::Nanoseconds,
23✔
93
                    fields::Second::Millisecond | fields::Second::Second => Self::Seconds,
228✔
94
                },
95
                _ => Self::None,
1,952✔
96
            },
97
            _ => Self::None,
2,539✔
98
        }
99
    }
5,471✔
100
}
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