use core::num::NonZero;
macro_rules! if_pub {
(pub $(#[$attr:meta])*; $($x:tt)*) => {
$(#[$attr])*
$($x)*
};
($($_:tt)*) => {};
}
macro_rules! impl_const_default {
($($(#[$doc:meta])* $(@$pub:ident)? $type:ty => $default:expr;)*) => {$(
impl $type {
if_pub! {
$($pub)?
$(#[$doc])*;
#[inline]
pub const fn default() -> Self {
$default
}
}
}
$(#[$doc])*
impl Default for $type {
#[inline]
fn default() -> Self {
$default
}
}
)*};
}
impl_const_default! {
@pub Day => Self { padding: Padding::Zero };
MonthRepr => Self::Numerical;
@pub Month => Self {
padding: Padding::Zero,
repr: MonthRepr::Numerical,
case_sensitive: true,
};
@pub Ordinal => Self { padding: Padding::Zero };
WeekdayRepr => Self::Long;
@pub Weekday => Self {
repr: WeekdayRepr::Long,
one_indexed: true,
case_sensitive: true,
};
WeekNumberRepr => Self::Iso;
@pub WeekNumber => Self {
padding: Padding::Zero,
repr: WeekNumberRepr::Iso,
};
YearRepr => Self::Full;
YearRange => Self::Extended;
@pub Year => Self {
padding: Padding::Zero,
repr: YearRepr::Full,
range: YearRange::Extended,
iso_week_based: false,
sign_is_mandatory: false,
};
@pub Hour => Self {
padding: Padding::Zero,
is_12_hour_clock: false,
};
@pub Minute => Self { padding: Padding::Zero };
@pub Period => Self {
is_uppercase: true,
case_sensitive: true,
};
@pub Second => Self { padding: Padding::Zero };
SubsecondDigits => Self::OneOrMore;
@pub Subsecond => Self { digits: SubsecondDigits::OneOrMore };
@pub OffsetHour => Self {
sign_is_mandatory: false,
padding: Padding::Zero,
};
@pub OffsetMinute => Self { padding: Padding::Zero };
@pub OffsetSecond => Self { padding: Padding::Zero };
Padding => Self::Zero;
UnixTimestampPrecision => Self::Second;
@pub UnixTimestamp => Self {
precision: UnixTimestampPrecision::Second,
sign_is_mandatory: false,
};
TrailingInput => Self::Prohibit;
@pub End => Self { trailing_input: TrailingInput::Prohibit };
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Day {
pub padding: Padding,
}
impl Day {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MonthRepr {
Numerical,
Long,
Short,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Month {
pub padding: Padding,
pub repr: MonthRepr,
pub case_sensitive: bool,
}
impl Month {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_repr(self, repr: MonthRepr) -> Self {
Self { repr, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
Self {
case_sensitive,
..self
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ordinal {
pub padding: Padding,
}
impl Ordinal {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WeekdayRepr {
Short,
Long,
Sunday,
Monday,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Weekday {
pub repr: WeekdayRepr,
pub one_indexed: bool,
pub case_sensitive: bool,
}
impl Weekday {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_repr(self, repr: WeekdayRepr) -> Self {
Self { repr, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
Self {
one_indexed,
..self
}
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
Self {
case_sensitive,
..self
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WeekNumberRepr {
Iso,
Sunday,
Monday,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WeekNumber {
pub padding: Padding,
pub repr: WeekNumberRepr,
}
impl WeekNumber {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_repr(self, repr: WeekNumberRepr) -> Self {
Self { repr, ..self }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YearRepr {
Full,
Century,
LastTwo,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YearRange {
Standard,
Extended,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Year {
pub padding: Padding,
pub repr: YearRepr,
pub range: YearRange,
pub iso_week_based: bool,
pub sign_is_mandatory: bool,
}
impl Year {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_repr(self, repr: YearRepr) -> Self {
Self { repr, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_range(self, range: YearRange) -> Self {
Self { range, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_iso_week_based(self, iso_week_based: bool) -> Self {
Self {
iso_week_based,
..self
}
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
Self {
sign_is_mandatory,
..self
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Hour {
pub padding: Padding,
pub is_12_hour_clock: bool,
}
impl Hour {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_is_12_hour_clock(self, is_12_hour_clock: bool) -> Self {
Self {
is_12_hour_clock,
..self
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Minute {
pub padding: Padding,
}
impl Minute {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Period {
pub is_uppercase: bool,
pub case_sensitive: bool,
}
impl Period {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_is_uppercase(self, is_uppercase: bool) -> Self {
Self {
is_uppercase,
..self
}
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
Self {
case_sensitive,
..self
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Second {
pub padding: Padding,
}
impl Second {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubsecondDigits {
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
OneOrMore,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Subsecond {
pub digits: SubsecondDigits,
}
impl Subsecond {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_digits(self, digits: SubsecondDigits) -> Self {
Self { digits }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetHour {
pub sign_is_mandatory: bool,
pub padding: Padding,
}
impl OffsetHour {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
Self {
sign_is_mandatory,
..self
}
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding, ..self }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetMinute {
pub padding: Padding,
}
impl OffsetMinute {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetSecond {
pub padding: Padding,
}
impl OffsetSecond {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_padding(self, padding: Padding) -> Self {
Self { padding }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Padding {
Space,
Zero,
None,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ignore {
pub count: NonZero<u16>,
}
impl Ignore {
#[inline]
pub const fn count(count: NonZero<u16>) -> Self {
Self { count }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_count(self, count: NonZero<u16>) -> Self {
Self { count }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnixTimestampPrecision {
Second,
Millisecond,
Microsecond,
Nanosecond,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UnixTimestamp {
pub precision: UnixTimestampPrecision,
pub sign_is_mandatory: bool,
}
impl UnixTimestamp {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_precision(self, precision: UnixTimestampPrecision) -> Self {
Self { precision, ..self }
}
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
Self {
sign_is_mandatory,
..self
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrailingInput {
Prohibit,
Discard,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct End {
pub(crate) trailing_input: TrailingInput,
}
impl End {
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn with_trailing_input(self, trailing_input: TrailingInput) -> Self {
Self {
trailing_input,
..self
}
}
}