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 ).
9 use icu_calendar::types::Time;
11 use crate::errors::ffi::ICU4XError;
14 /// An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond
15 #[diplomat::rust_link(icu::calendar::types::Time, Struct)]
16 pub struct ICU4XTime(pub Time);
19 /// Creates a new [`ICU4XTime`] given field values
20 #[diplomat::rust_link(icu::calendar::types::Time, Struct)]
26 ) -> Result<Box<ICU4XTime>, ICU4XError> {
27 let hour = hour.try_into()?;
28 let minute = minute.try_into()?;
29 let second = second.try_into()?;
30 let nanosecond = nanosecond.try_into()?;
37 Ok(Box::new(ICU4XTime(time)))
40 /// Creates a new [`ICU4XTime`] representing midnight (00:00.000).
41 #[diplomat::rust_link(icu::calendar::types::Time, Struct)]
42 pub fn create_midnight() -> Result<Box<ICU4XTime>, ICU4XError> {
43 let time = Time::midnight();
44 Ok(Box::new(ICU4XTime(time)))
47 /// Returns the hour in this time
48 #[diplomat::rust_link(icu::calendar::types::Time::hour, StructField)]
49 pub fn hour(&self) -> u8 {
52 /// Returns the minute in this time
53 #[diplomat::rust_link(icu::calendar::types::Time::minute, StructField)]
54 pub fn minute(&self) -> u8 {
57 /// Returns the second in this time
58 #[diplomat::rust_link(icu::calendar::types::Time::second, StructField)]
59 pub fn second(&self) -> u8 {
62 /// Returns the nanosecond in this time
63 #[diplomat::rust_link(icu::calendar::types::Time::nanosecond, StructField)]
64 pub fn nanosecond(&self) -> u32 {
65 self.0.nanosecond.into()