#[cfg(feature = "serde")]
use crate::neo_serde::*;
#[cfg(feature = "datagen")]
use crate::options::{self, length};
use crate::pattern::CoarseHourCycle;
use crate::raw::neo::MaybeLength;
use crate::time_zone::ResolvedNeoTimeZoneSkeleton;
use icu_provider::DataMarkerAttributes;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[repr(u8)] #[non_exhaustive]
pub enum NeoSkeletonLength {
Long = 4,
Medium = 3,
Short = 1,
}
impl NeoSkeletonLength {
pub const VALUES: &'static [Self] = &[Self::Long, Self::Medium, Self::Short];
#[cfg(feature = "datagen")]
pub fn to_date_style(self) -> options::length::Date {
match self {
Self::Long => options::length::Date::Long,
Self::Medium => options::length::Date::Medium,
Self::Short => options::length::Date::Short,
}
}
#[cfg(feature = "datagen")]
pub fn to_time_style(self) -> options::length::Time {
match self {
Self::Long => options::length::Time::Medium,
Self::Medium => options::length::Time::Medium,
Self::Short => options::length::Time::Short,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[non_exhaustive]
pub enum Alignment {
Auto,
Column,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[non_exhaustive]
pub enum EraDisplay {
Auto,
Always,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(try_from = "u8", into = "u8"))]
#[non_exhaustive]
pub enum FractionalSecondDigits {
F0,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, displaydoc::Display)]
#[non_exhaustive]
pub enum FractionalSecondError {
OutOfRange,
}
impl From<FractionalSecondDigits> for u8 {
fn from(value: FractionalSecondDigits) -> u8 {
use FractionalSecondDigits::*;
match value {
F0 => 0,
F1 => 1,
F2 => 2,
F3 => 3,
F4 => 4,
F5 => 5,
F6 => 6,
F7 => 7,
F8 => 8,
F9 => 9,
}
}
}
impl TryFrom<u8> for FractionalSecondDigits {
type Error = FractionalSecondError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
use FractionalSecondDigits::*;
match value {
0 => Ok(F0),
1 => Ok(F1),
2 => Ok(F2),
3 => Ok(F3),
4 => Ok(F4),
5 => Ok(F5),
6 => Ok(F6),
7 => Ok(F7),
8 => Ok(F8),
9 => Ok(F9),
_ => Err(FractionalSecondError::OutOfRange),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NeoDayComponents {
Day,
MonthDay,
YearMonthDay,
EraYearMonthDay,
DayWeekday,
MonthDayWeekday,
YearMonthDayWeekday,
EraYearMonthDayWeekday,
Weekday,
Auto,
AutoWeekday,
}
impl NeoDayComponents {
pub const VALUES: &'static [Self] = &[
Self::Day,
Self::MonthDay,
Self::YearMonthDay,
Self::EraYearMonthDay,
Self::DayWeekday,
Self::MonthDayWeekday,
Self::YearMonthDayWeekday,
Self::EraYearMonthDayWeekday,
Self::Weekday,
Self::Auto,
Self::AutoWeekday,
];
const DAY: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("d");
const MONTH_DAY: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("m0d");
const YEAR_MONTH_DAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("ym0d");
const ERA_YEAR_MONTH_DAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("gym0d");
const DAY_WEEKDAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("de");
const MONTH_DAY_WEEKDAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("m0de");
const YEAR_MONTH_DAY_WEEKDAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("ym0de");
const ERA_YEAR_MONTH_DAY_WEEKDAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("gym0de");
const WEEKDAY: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("e");
const AUTO: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("a1");
const AUTO_WEEKDAY: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("a1e");
const DAY_STR: &'static str = Self::DAY.as_str();
const MONTH_DAY_STR: &'static str = Self::MONTH_DAY.as_str();
const YEAR_MONTH_DAY_STR: &'static str = Self::YEAR_MONTH_DAY.as_str();
const ERA_YEAR_MONTH_DAY_STR: &'static str = Self::ERA_YEAR_MONTH_DAY.as_str();
const DAY_WEEKDAY_STR: &'static str = Self::DAY_WEEKDAY.as_str();
const MONTH_DAY_WEEKDAY_STR: &'static str = Self::MONTH_DAY_WEEKDAY.as_str();
const YEAR_MONTH_DAY_WEEKDAY_STR: &'static str = Self::YEAR_MONTH_DAY_WEEKDAY.as_str();
const ERA_YEAR_MONTH_DAY_WEEKDAY_STR: &'static str = Self::ERA_YEAR_MONTH_DAY_WEEKDAY.as_str();
const WEEKDAY_STR: &'static str = Self::WEEKDAY.as_str();
const AUTO_STR: &'static str = Self::AUTO.as_str();
const AUTO_WEEKDAY_STR: &'static str = Self::AUTO_WEEKDAY.as_str();
pub const fn id_str(self) -> &'static DataMarkerAttributes {
match self {
Self::Day => Self::DAY,
Self::MonthDay => Self::MONTH_DAY,
Self::YearMonthDay => Self::YEAR_MONTH_DAY,
Self::EraYearMonthDay => Self::ERA_YEAR_MONTH_DAY,
Self::DayWeekday => Self::DAY_WEEKDAY,
Self::MonthDayWeekday => Self::MONTH_DAY_WEEKDAY,
Self::YearMonthDayWeekday => Self::YEAR_MONTH_DAY_WEEKDAY,
Self::EraYearMonthDayWeekday => Self::ERA_YEAR_MONTH_DAY_WEEKDAY,
Self::Weekday => Self::WEEKDAY,
Self::Auto => Self::AUTO,
Self::AutoWeekday => Self::AUTO_WEEKDAY,
}
}
pub fn from_id_str(id_str: &DataMarkerAttributes) -> Option<Self> {
match &**id_str {
Self::DAY_STR => Some(Self::Day),
Self::MONTH_DAY_STR => Some(Self::MonthDay),
Self::YEAR_MONTH_DAY_STR => Some(Self::YearMonthDay),
Self::ERA_YEAR_MONTH_DAY_STR => Some(Self::EraYearMonthDay),
Self::DAY_WEEKDAY_STR => Some(Self::DayWeekday),
Self::MONTH_DAY_WEEKDAY_STR => Some(Self::MonthDayWeekday),
Self::YEAR_MONTH_DAY_WEEKDAY_STR => Some(Self::YearMonthDayWeekday),
Self::ERA_YEAR_MONTH_DAY_WEEKDAY_STR => Some(Self::EraYearMonthDayWeekday),
Self::WEEKDAY_STR => Some(Self::Weekday),
Self::AUTO_STR => Some(Self::Auto),
Self::AUTO_WEEKDAY_STR => Some(Self::AutoWeekday),
_ => None,
}
}
pub fn has_full_year(self) -> bool {
match self {
Self::Day => false,
Self::MonthDay => false,
Self::YearMonthDay => false,
Self::EraYearMonthDay => true,
Self::DayWeekday => false,
Self::MonthDayWeekday => false,
Self::YearMonthDayWeekday => false,
Self::EraYearMonthDayWeekday => true,
Self::Weekday => false,
Self::Auto => false,
Self::AutoWeekday => false,
}
}
pub fn has_year(self) -> bool {
match self {
Self::Day => false,
Self::MonthDay => false,
Self::YearMonthDay => true,
Self::EraYearMonthDay => true,
Self::DayWeekday => false,
Self::MonthDayWeekday => false,
Self::YearMonthDayWeekday => true,
Self::EraYearMonthDayWeekday => true,
Self::Weekday => false,
Self::Auto => true,
Self::AutoWeekday => true,
}
}
pub fn has_month(self) -> bool {
match self {
Self::Day => false,
Self::MonthDay => true,
Self::YearMonthDay => true,
Self::EraYearMonthDay => true,
Self::DayWeekday => false,
Self::MonthDayWeekday => true,
Self::YearMonthDayWeekday => true,
Self::EraYearMonthDayWeekday => true,
Self::Weekday => false,
Self::Auto => true,
Self::AutoWeekday => true,
}
}
pub fn has_day(self) -> bool {
match self {
Self::Day => true,
Self::MonthDay => true,
Self::YearMonthDay => true,
Self::EraYearMonthDay => true,
Self::DayWeekday => true,
Self::MonthDayWeekday => true,
Self::YearMonthDayWeekday => true,
Self::EraYearMonthDayWeekday => true,
Self::Weekday => false,
Self::Auto => true,
Self::AutoWeekday => true,
}
}
pub fn has_weekday(self) -> bool {
match self {
Self::Day => false,
Self::MonthDay => false,
Self::YearMonthDay => false,
Self::EraYearMonthDay => false,
Self::DayWeekday => true,
Self::MonthDayWeekday => true,
Self::YearMonthDayWeekday => true,
Self::EraYearMonthDayWeekday => true,
Self::Weekday => true,
Self::Auto => false,
Self::AutoWeekday => true,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NeoDateComponents {
Day(NeoDayComponents),
Month,
YearMonth,
EraYearMonth,
Year,
EraYear,
YearWeek,
}
impl NeoDateComponents {
pub const VALUES: &'static [Self] = &[
Self::Day(NeoDayComponents::Day),
Self::Day(NeoDayComponents::MonthDay),
Self::Day(NeoDayComponents::YearMonthDay),
Self::Day(NeoDayComponents::EraYearMonthDay),
Self::Day(NeoDayComponents::DayWeekday),
Self::Day(NeoDayComponents::MonthDayWeekday),
Self::Day(NeoDayComponents::YearMonthDayWeekday),
Self::Day(NeoDayComponents::EraYearMonthDayWeekday),
Self::Day(NeoDayComponents::Weekday),
Self::Day(NeoDayComponents::Auto),
Self::Day(NeoDayComponents::AutoWeekday),
Self::Month,
Self::YearMonth,
Self::EraYearMonth,
Self::Year,
Self::EraYear,
Self::YearWeek,
];
const MONTH: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("m0");
const YEAR_MONTH: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("ym0");
const ERA_YEAR_MONTH: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("gym0");
const YEAR: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("y");
const ERA_YEAR: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("gy");
const YEAR_WEEK: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("y0w");
const MONTH_STR: &'static str = Self::MONTH.as_str();
const YEAR_MONTH_STR: &'static str = Self::YEAR_MONTH.as_str();
const ERA_YEAR_MONTH_STR: &'static str = Self::ERA_YEAR_MONTH.as_str();
const YEAR_STR: &'static str = Self::YEAR.as_str();
const ERA_YEAR_STR: &'static str = Self::ERA_YEAR.as_str();
const YEAR_WEEK_STR: &'static str = Self::YEAR_WEEK.as_str();
pub const fn id_str(self) -> &'static DataMarkerAttributes {
match self {
Self::Day(day_components) => day_components.id_str(),
Self::Month => Self::MONTH,
Self::YearMonth => Self::YEAR_MONTH,
Self::EraYearMonth => Self::ERA_YEAR_MONTH,
Self::Year => Self::YEAR,
Self::EraYear => Self::ERA_YEAR,
Self::YearWeek => Self::YEAR_WEEK,
}
}
pub fn from_id_str(id_str: &DataMarkerAttributes) -> Option<Self> {
match &**id_str {
Self::MONTH_STR => Some(Self::Month),
Self::YEAR_MONTH_STR => Some(Self::YearMonth),
Self::ERA_YEAR_MONTH_STR => Some(Self::EraYearMonth),
Self::YEAR_STR => Some(Self::Year),
Self::ERA_YEAR_STR => Some(Self::EraYear),
Self::YEAR_WEEK_STR => Some(Self::YearWeek),
_ => NeoDayComponents::from_id_str(id_str).map(Self::Day),
}
}
pub fn has_full_year(self) -> bool {
match self {
Self::Day(day_components) => day_components.has_full_year(),
Self::Month => false,
Self::YearMonth => false,
Self::EraYearMonth => true,
Self::Year => false,
Self::EraYear => true,
Self::YearWeek => false,
}
}
pub fn has_year(self) -> bool {
match self {
Self::Day(day_components) => day_components.has_year(),
Self::Month => false,
Self::YearMonth => true,
Self::EraYearMonth => true,
Self::Year => true,
Self::EraYear => true,
Self::YearWeek => true,
}
}
pub fn has_month(self) -> bool {
match self {
Self::Day(day_components) => day_components.has_month(),
Self::Month => true,
Self::YearMonth => true,
Self::EraYearMonth => true,
Self::Year => false,
Self::EraYear => false,
Self::YearWeek => false,
}
}
pub fn has_day(self) -> bool {
match self {
Self::Day(day_components) => day_components.has_day(),
_ => false,
}
}
pub fn has_weekday(self) -> bool {
match self {
Self::Day(day_components) => day_components.has_weekday(),
_ => false,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NeoTimeComponents {
Hour,
HourMinute,
HourMinuteSecond,
DayPeriodHour12,
Hour12,
DayPeriodHour12Minute,
Hour12Minute,
DayPeriodHour12MinuteSecond,
Hour12MinuteSecond,
Hour24,
Hour24Minute,
Hour24MinuteSecond,
Auto,
}
impl NeoTimeComponents {
pub const VALUES: &'static [Self] = &[
Self::Hour,
Self::HourMinute,
Self::HourMinuteSecond,
Self::DayPeriodHour12,
Self::Hour12,
Self::DayPeriodHour12Minute,
Self::Hour12Minute,
Self::DayPeriodHour12MinuteSecond,
Self::Hour12MinuteSecond,
Self::Hour24,
Self::Hour24Minute,
Self::Hour24MinuteSecond,
Self::Auto,
];
const HOUR: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("j");
const HOUR_MINUTE: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("jm");
const HOUR_MINUTE_SECOND: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("jms");
const DAY_PERIOD_HOUR12: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("bh");
const HOUR12: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("h");
const DAY_PERIOD_HOUR12_MINUTE: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("bhm");
const HOUR12_MINUTE: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("hm");
const DAY_PERIOD_HOUR12_MINUTE_SECOND: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("bhms");
const HOUR12_MINUTE_SECOND: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("hms");
const HOUR24: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("h0");
const HOUR24_MINUTE: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("h0m");
const HOUR24_MINUTE_SECOND: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("h0ms");
const AUTO: &'static DataMarkerAttributes = DataMarkerAttributes::from_str_or_panic("a1");
const HOUR_STR: &'static str = Self::HOUR.as_str();
const HOUR_MINUTE_STR: &'static str = Self::HOUR_MINUTE.as_str();
const HOUR_MINUTE_SECOND_STR: &'static str = Self::HOUR_MINUTE_SECOND.as_str();
const DAY_PERIOD_HOUR12_STR: &'static str = Self::DAY_PERIOD_HOUR12.as_str();
const HOUR12_STR: &'static str = Self::HOUR12.as_str();
const DAY_PERIOD_HOUR12_MINUTE_STR: &'static str = Self::DAY_PERIOD_HOUR12_MINUTE.as_str();
const HOUR12_MINUTE_STR: &'static str = Self::HOUR12_MINUTE.as_str();
const DAY_PERIOD_HOUR12_MINUTE_SECOND_STR: &'static str =
Self::DAY_PERIOD_HOUR12_MINUTE_SECOND.as_str();
const HOUR12_MINUTE_SECOND_STR: &'static str = Self::HOUR12_MINUTE_SECOND.as_str();
const HOUR24_STR: &'static str = Self::HOUR24.as_str();
const HOUR24_MINUTE_STR: &'static str = Self::HOUR24_MINUTE.as_str();
const HOUR24_MINUTE_SECOND_STR: &'static str = Self::HOUR24_MINUTE_SECOND.as_str();
const AUTO_STR: &'static str = Self::AUTO.as_str();
pub const fn id_str(self) -> &'static DataMarkerAttributes {
match self {
Self::Hour => Self::HOUR,
Self::HourMinute => Self::HOUR_MINUTE,
Self::HourMinuteSecond => Self::HOUR_MINUTE_SECOND,
Self::DayPeriodHour12 => Self::DAY_PERIOD_HOUR12,
Self::Hour12 => Self::HOUR12,
Self::DayPeriodHour12Minute => Self::DAY_PERIOD_HOUR12_MINUTE,
Self::Hour12Minute => Self::HOUR12_MINUTE,
Self::DayPeriodHour12MinuteSecond => Self::DAY_PERIOD_HOUR12_MINUTE_SECOND,
Self::Hour12MinuteSecond => Self::HOUR12_MINUTE_SECOND,
Self::Hour24 => Self::HOUR24,
Self::Hour24Minute => Self::HOUR24_MINUTE,
Self::Hour24MinuteSecond => Self::HOUR24_MINUTE_SECOND,
Self::Auto => Self::AUTO,
}
}
pub fn from_id_str(id_str: &DataMarkerAttributes) -> Option<Self> {
match &**id_str {
Self::HOUR_STR => Some(Self::Hour),
Self::HOUR_MINUTE_STR => Some(Self::HourMinute),
Self::HOUR_MINUTE_SECOND_STR => Some(Self::HourMinuteSecond),
Self::DAY_PERIOD_HOUR12_STR => Some(Self::DayPeriodHour12),
Self::HOUR12_STR => Some(Self::Hour12),
Self::DAY_PERIOD_HOUR12_MINUTE_STR => Some(Self::DayPeriodHour12Minute),
Self::HOUR12_MINUTE_STR => Some(Self::Hour12Minute),
Self::DAY_PERIOD_HOUR12_MINUTE_SECOND_STR => Some(Self::DayPeriodHour12MinuteSecond),
Self::HOUR12_MINUTE_SECOND_STR => Some(Self::Hour12MinuteSecond),
Self::HOUR24_STR => Some(Self::Hour24),
Self::HOUR24_MINUTE_STR => Some(Self::Hour24Minute),
Self::HOUR24_MINUTE_SECOND_STR => Some(Self::Hour24MinuteSecond),
Self::AUTO_STR => Some(Self::Auto),
_ => None,
}
}
pub(crate) fn with_hour_cycle(self, hour_cycle: CoarseHourCycle) -> Self {
use CoarseHourCycle::*;
match (self, hour_cycle) {
(Self::Hour, H11H12) => Self::Hour12,
(Self::HourMinute, H11H12) => Self::Hour12Minute,
(Self::HourMinuteSecond, H11H12) => Self::Hour12MinuteSecond,
(Self::Hour, H23H24) => Self::Hour24,
(Self::HourMinute, H23H24) => Self::Hour24Minute,
(Self::HourMinuteSecond, H23H24) => Self::Hour24MinuteSecond,
_ => self,
}
}
#[doc(hidden)] #[cfg(feature = "datagen")]
pub fn from_time_length(time_length: length::Time) -> Self {
match time_length {
length::Time::Full => todo!(),
length::Time::Long => todo!(),
length::Time::Medium => NeoTimeComponents::HourMinuteSecond,
length::Time::Short => NeoTimeComponents::HourMinute,
}
}
pub fn has_hour(self) -> bool {
true
}
pub fn has_minute(self) -> bool {
matches!(
self,
NeoTimeComponents::HourMinute
| NeoTimeComponents::Hour12Minute
| NeoTimeComponents::Hour24Minute
| NeoTimeComponents::HourMinuteSecond
| NeoTimeComponents::Hour12MinuteSecond
| NeoTimeComponents::Hour24MinuteSecond
)
}
pub fn has_second(self) -> bool {
matches!(
self,
NeoTimeComponents::HourMinuteSecond
| NeoTimeComponents::Hour12MinuteSecond
| NeoTimeComponents::Hour24MinuteSecond
)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NeoDateTimeComponents {
Date(NeoDateComponents),
Time(NeoTimeComponents),
DateTime(NeoDayComponents, NeoTimeComponents),
}
impl From<NeoDateComponents> for NeoDateTimeComponents {
fn from(value: NeoDateComponents) -> Self {
Self::Date(value)
}
}
impl From<NeoTimeComponents> for NeoDateTimeComponents {
fn from(value: NeoTimeComponents) -> Self {
Self::Time(value)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(try_from = "FieldSetSerde", into = "FieldSetSerde")
)]
#[non_exhaustive]
pub enum NeoComponents {
Date(NeoDateComponents),
Time(NeoTimeComponents),
Zone(NeoTimeZoneSkeleton),
DateTime(NeoDayComponents, NeoTimeComponents),
DateZone(NeoDateComponents, NeoTimeZoneSkeleton),
TimeZone(NeoTimeComponents, NeoTimeZoneSkeleton),
DateTimeZone(NeoDayComponents, NeoTimeComponents, NeoTimeZoneSkeleton),
}
impl From<NeoDateComponents> for NeoComponents {
fn from(value: NeoDateComponents) -> Self {
Self::Date(value)
}
}
impl From<NeoTimeComponents> for NeoComponents {
fn from(value: NeoTimeComponents) -> Self {
Self::Time(value)
}
}
impl From<NeoDateTimeComponents> for NeoComponents {
fn from(value: NeoDateTimeComponents) -> Self {
match value {
NeoDateTimeComponents::Date(components) => components.into(),
NeoDateTimeComponents::Time(components) => components.into(),
NeoDateTimeComponents::DateTime(day, time) => NeoComponents::DateTime(day, time),
}
}
}
impl From<NeoTimeZoneSkeleton> for NeoComponents {
fn from(value: NeoTimeZoneSkeleton) -> Self {
Self::Zone(value)
}
}
impl NeoComponents {
const WEEKDAY_HOUR_MINUTE: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("ejm");
const WEEKDAY_HOUR_MINUTE_SECOND: &'static DataMarkerAttributes =
DataMarkerAttributes::from_str_or_panic("ejms");
const WEEKDAY_HOUR_MINUTE_STR: &'static str = Self::WEEKDAY_HOUR_MINUTE.as_str();
const WEEKDAY_HOUR_MINUTE_SECOND_STR: &'static str = Self::WEEKDAY_HOUR_MINUTE_SECOND.as_str();
#[doc(hidden)] pub fn attributes_with_overrides() -> &'static [&'static DataMarkerAttributes] {
&[Self::WEEKDAY_HOUR_MINUTE, Self::WEEKDAY_HOUR_MINUTE_SECOND]
}
pub const fn id_str(self) -> Option<&'static DataMarkerAttributes> {
match self {
Self::DateTime(NeoDayComponents::Weekday, NeoTimeComponents::HourMinute) => {
Some(Self::WEEKDAY_HOUR_MINUTE)
}
Self::DateTime(NeoDayComponents::Weekday, NeoTimeComponents::HourMinuteSecond) => {
Some(Self::WEEKDAY_HOUR_MINUTE_SECOND)
}
_ => None,
}
}
pub fn from_id_str(id_str: &DataMarkerAttributes) -> Option<Self> {
match &**id_str {
Self::WEEKDAY_HOUR_MINUTE_STR => Some(Self::DateTime(
NeoDayComponents::Weekday,
NeoTimeComponents::HourMinute,
)),
Self::WEEKDAY_HOUR_MINUTE_SECOND_STR => Some(Self::DateTime(
NeoDayComponents::Weekday,
NeoTimeComponents::HourMinuteSecond,
)),
_ => None,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum NeoTimeZoneStyle {
#[default]
Default,
Location,
NonLocation,
SpecificNonLocation,
Offset,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub struct NeoTimeZoneSkeleton {
pub length: Option<NeoSkeletonLength>,
pub style: NeoTimeZoneStyle,
}
impl NeoTimeZoneSkeleton {
pub(crate) fn resolve(self, length: MaybeLength) -> ResolvedNeoTimeZoneSkeleton {
crate::tz_registry::skeleton_to_resolved(
self.style,
self.length.unwrap_or_else(|| length.get::<Self>()),
)
}
}
#[derive(Debug, Copy, Clone)]
#[allow(clippy::exhaustive_structs)] pub struct NeoDateSkeleton {
pub length: NeoSkeletonLength,
pub components: NeoDateComponents,
pub alignment: Option<Alignment>,
pub era_display: Option<EraDisplay>,
}
impl NeoDateSkeleton {
pub fn for_length_and_components(
length: NeoSkeletonLength,
components: NeoDateComponents,
) -> Self {
Self {
length,
components,
alignment: None,
era_display: None,
}
}
#[doc(hidden)] #[cfg(feature = "datagen")]
pub fn day_from_date_length(
date_length: length::Date,
) -> (NeoDayComponents, NeoSkeletonLength) {
match date_length {
length::Date::Full => (NeoDayComponents::AutoWeekday, NeoSkeletonLength::Long),
length::Date::Long => (NeoDayComponents::Auto, NeoSkeletonLength::Long),
length::Date::Medium => (NeoDayComponents::Auto, NeoSkeletonLength::Medium),
length::Date::Short => (NeoDayComponents::Auto, NeoSkeletonLength::Short),
}
}
#[doc(hidden)] #[cfg(feature = "datagen")]
pub fn from_date_length(date_length: length::Date) -> Self {
let (day_components, length) = Self::day_from_date_length(date_length);
NeoDateSkeleton {
length,
components: NeoDateComponents::Day(day_components),
alignment: None,
era_display: None,
}
}
}
#[derive(Debug, Copy, Clone)]
#[allow(clippy::exhaustive_structs)] pub struct NeoTimeSkeleton {
pub length: NeoSkeletonLength,
pub components: NeoTimeComponents,
pub alignment: Option<Alignment>,
pub fractional_second_digits: Option<FractionalSecondDigits>,
}
impl NeoTimeSkeleton {
pub fn for_length_and_components(
length: NeoSkeletonLength,
components: NeoTimeComponents,
) -> Self {
Self {
length,
components,
alignment: None,
fractional_second_digits: None,
}
}
}
#[derive(Debug, Copy, Clone)]
#[allow(clippy::exhaustive_structs)] pub struct NeoDateTimeSkeleton {
pub length: NeoSkeletonLength,
pub components: NeoDateTimeComponents,
pub alignment: Option<Alignment>,
pub era_display: Option<EraDisplay>,
pub fractional_second_digits: Option<FractionalSecondDigits>,
}
impl NeoDateTimeSkeleton {
pub fn for_length_and_components(
length: NeoSkeletonLength,
date: NeoDayComponents,
time: NeoTimeComponents,
) -> Self {
Self {
length,
components: NeoDateTimeComponents::DateTime(date, time),
alignment: None,
era_display: None,
fractional_second_digits: None,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(try_from = "SemanticSkeletonSerde", into = "SemanticSkeletonSerde")
)]
#[non_exhaustive]
pub struct NeoSkeleton {
pub length: NeoSkeletonLength,
pub components: NeoComponents,
pub alignment: Option<Alignment>,
pub era_display: Option<EraDisplay>,
pub fractional_second_digits: Option<FractionalSecondDigits>,
}
impl From<NeoDateSkeleton> for NeoSkeleton {
fn from(value: NeoDateSkeleton) -> Self {
NeoSkeleton {
length: value.length,
components: value.components.into(),
alignment: value.alignment,
era_display: value.era_display,
fractional_second_digits: None,
}
}
}
impl From<NeoTimeSkeleton> for NeoSkeleton {
fn from(value: NeoTimeSkeleton) -> Self {
NeoSkeleton {
length: value.length,
components: value.components.into(),
alignment: value.alignment,
era_display: None,
fractional_second_digits: value.fractional_second_digits,
}
}
}
impl From<NeoDateTimeSkeleton> for NeoSkeleton {
fn from(value: NeoDateTimeSkeleton) -> Self {
NeoSkeleton {
length: value.length,
components: value.components.into(),
alignment: value.alignment,
era_display: value.era_display,
fractional_second_digits: value.fractional_second_digits,
}
}
}
impl NeoDateTimeSkeleton {
#[doc(hidden)] #[cfg(feature = "datagen")]
pub fn from_date_time_length(
date_length: crate::options::length::Date,
time_length: crate::options::length::Time,
) -> Self {
let (day_components, length) = NeoDateSkeleton::day_from_date_length(date_length);
let time_components = NeoTimeComponents::from_time_length(time_length);
NeoDateTimeSkeleton {
length,
components: NeoDateTimeComponents::DateTime(day_components, time_components),
alignment: None,
era_display: None,
fractional_second_digits: None,
}
}
}