| 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 |
use icu_calendar::Gregorian; |
| 6 |
|
| 7 |
use crate::zone::UtcOffset; |
| 8 |
#[cfg(feature = "compiled_data")] |
| 9 |
use crate::zone::ZoneNameTimestamp; |
| 10 |
#[cfg(feature = "compiled_data")] |
| 11 |
use crate::zone::models::{AtTime, Base}; |
| 12 |
use crate::{DateTime, Hour, Minute, Nanosecond, Second, Time}; |
| 13 |
#[cfg(feature = "compiled_data")] |
| 14 |
use crate::{TimeZone, TimeZoneInfo, ZonedDateTime}; |
| 15 |
|
| 16 |
impl From<jiff::civil::Time> for Time { |
| 17 |
fn from(jiff: jiff::civil::Time) -> Self { |
| 18 |
Time { |
| 19 |
hour: Hour(jiff.hour() as u8), |
| 20 |
minute: Minute(jiff.minute() as u8), |
| 21 |
second: Second(jiff.second() as u8), |
| 22 |
subsecond: Nanosecond( |
| 23 |
jiff.millisecond() as u32 * 1_000_000 |
| 24 |
+ jiff.microsecond() as u32 * 1_000 |
| 25 |
+ jiff.nanosecond() as u32, |
| 26 |
), |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl From<jiff::civil::DateTime> for DateTime<Gregorian> { |
| 32 |
fn from(jiff: jiff::civil::DateTime) -> Self { |
| 33 |
Self { |
| 34 |
date: jiff.date().into(), |
| 35 |
time: jiff.time().into(), |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
impl From<jiff::tz::Offset> for UtcOffset { |
| 41 |
fn from(jiff: jiff::tz::Offset) -> Self { |
| 42 |
UtcOffset::from_seconds_unchecked(jiff.seconds()) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
#[cfg(feature = "compiled_data")] |
| 47 |
impl From<&jiff::tz::TimeZone> for TimeZone { |
| 48 |
fn from(jiff: &jiff::tz::TimeZone) -> Self { |
| 49 |
jiff.iana_name() |
| 50 |
.map(|i| crate::zone::IanaParser::new().parse(i)) |
| 51 |
.unwrap_or(TimeZone::UNKNOWN) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
#[cfg(feature = "compiled_data")] |
| 56 |
impl From<&jiff::Zoned> for ZonedDateTime<Gregorian, TimeZoneInfo<Base>> { |
| 57 |
fn from(jiff: &jiff::Zoned) -> Self { |
| 58 |
let date = jiff.date().into(); |
| 59 |
let time = jiff.time().into(); |
| 60 |
let zone = TimeZone::from(jiff.time_zone()).with_offset(Some(jiff.offset().into())); |
| 61 |
|
| 62 |
ZonedDateTime { date, time, zone } |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
#[cfg(feature = "compiled_data")] |
| 67 |
impl From<&jiff::Zoned> for ZonedDateTime<Gregorian, TimeZoneInfo<AtTime>> { |
| 68 |
fn from(jiff: &jiff::Zoned) -> Self { |
| 69 |
let ZonedDateTime::<_, TimeZoneInfo<Base>> { date, time, zone } = jiff.into(); |
| 70 |
|
| 71 |
ZonedDateTime { |
| 72 |
date, |
| 73 |
time, |
| 74 |
zone: zone.with_zone_name_timestamp(ZoneNameTimestamp::from_epoch_seconds( |
| 75 |
jiff.timestamp().as_second(), |
| 76 |
)), |
| 77 |
} |
| 78 |
} |
| 79 |
} |