summaryrefslogtreecommitdiffstats
path: root/vendor/time/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/time/src
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src')
-rw-r--r--vendor/time/src/date.rs100
-rw-r--r--vendor/time/src/date_time.rs57
-rw-r--r--vendor/time/src/ext.rs47
-rw-r--r--vendor/time/src/formatting/mod.rs29
-rw-r--r--vendor/time/src/month.rs38
-rw-r--r--vendor/time/src/offset_date_time.rs22
-rw-r--r--vendor/time/src/parsing/iso8601.rs1
-rw-r--r--vendor/time/src/primitive_date_time.rs23
-rw-r--r--vendor/time/src/tests.rs2
-rw-r--r--vendor/time/src/time.rs69
-rw-r--r--vendor/time/src/utc_offset.rs52
-rw-r--r--vendor/time/src/weekday.rs36
12 files changed, 391 insertions, 85 deletions
diff --git a/vendor/time/src/date.rs b/vendor/time/src/date.rs
index 3f76adb2d..5e62dfabc 100644
--- a/vendor/time/src/date.rs
+++ b/vendor/time/src/date.rs
@@ -1,15 +1,18 @@
//! The [`Date`] struct and its associated `impl`s.
-use core::fmt;
use core::num::NonZeroI32;
use core::ops::{Add, Sub};
use core::time::Duration as StdDuration;
+use core::{cmp, fmt};
#[cfg(feature = "formatting")]
use std::io;
use deranged::RangedI32;
+use powerfmt::ext::FormatterExt;
+use powerfmt::smart_display::{self, FormatterOptions, Metadata, SmartDisplay};
use crate::convert::*;
+use crate::ext::DigitCount;
#[cfg(feature = "formatting")]
use crate::formatting::Formattable;
use crate::internal_macros::{
@@ -1303,29 +1306,92 @@ impl Date {
}
}
-impl fmt::Display for Date {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if cfg!(feature = "large-dates") && self.year().abs() >= 10_000 {
- write!(
- f,
- "{:+}-{:02}-{:02}",
- self.year(),
- self.month() as u8,
- self.day()
+mod private {
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct DateMetadata {
+ /// The width of the year component, including the sign.
+ pub(super) year_width: u8,
+ /// Whether the sign should be displayed.
+ pub(super) display_sign: bool,
+ pub(super) year: i32,
+ pub(super) month: u8,
+ pub(super) day: u8,
+ }
+}
+use private::DateMetadata;
+
+impl SmartDisplay for Date {
+ type Metadata = DateMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<Self> {
+ let (year, month, day) = self.to_calendar_date();
+
+ // There is a minimum of four digits for any year.
+ let mut year_width = cmp::max(year.unsigned_abs().num_digits(), 4);
+ let display_sign = if !(0..10_000).contains(&year) {
+ // An extra character is required for the sign.
+ year_width += 1;
+ true
+ } else {
+ false
+ };
+
+ let formatted_width = year_width as usize
+ + smart_display::padded_width_of!(
+ "-",
+ month as u8 => width(2),
+ "-",
+ day => width(2),
+ );
+
+ Metadata::new(
+ formatted_width,
+ self,
+ DateMetadata {
+ year_width,
+ display_sign,
+ year,
+ month: month as u8,
+ day,
+ },
+ )
+ }
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ let DateMetadata {
+ year_width,
+ display_sign,
+ year,
+ month,
+ day,
+ } = *metadata;
+ let year_width = year_width as usize;
+
+ if display_sign {
+ f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!("{year:+0year_width$}-{month:02}-{day:02}"),
)
} else {
- write!(
- f,
- "{:0width$}-{:02}-{:02}",
- self.year(),
- self.month() as u8,
- self.day(),
- width = 4 + (self.year() < 0) as usize
+ f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!("{year:0year_width$}-{month:02}-{day:02}"),
)
}
}
}
+impl fmt::Display for Date {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ SmartDisplay::fmt(self, f)
+ }
+}
+
impl fmt::Debug for Date {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
fmt::Display::fmt(self, f)
diff --git a/vendor/time/src/date_time.rs b/vendor/time/src/date_time.rs
index 53cae5eb4..27f07cec8 100644
--- a/vendor/time/src/date_time.rs
+++ b/vendor/time/src/date_time.rs
@@ -17,6 +17,8 @@ use std::io;
use std::time::SystemTime;
use deranged::RangedI64;
+use powerfmt::ext::FormatterExt;
+use powerfmt::smart_display::{self, FormatterOptions, Metadata, SmartDisplay};
use crate::convert::*;
use crate::date::{MAX_YEAR, MIN_YEAR};
@@ -911,23 +913,60 @@ impl<O: MaybeOffset> DateTime<O> {
// endregion deprecated time getters
}
-impl<O: MaybeOffset> fmt::Debug for DateTime<O> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- <Self as fmt::Display>::fmt(self, f)
+// region: trait impls
+mod private {
+ use super::*;
+
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct DateTimeMetadata {
+ pub(super) maybe_offset: Option<UtcOffset>,
+ }
+}
+pub(crate) use private::DateTimeMetadata;
+
+impl<O: MaybeOffset> SmartDisplay for DateTime<O> {
+ type Metadata = DateTimeMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<Self> {
+ let maybe_offset = maybe_offset_as_offset_opt::<O>(self.offset);
+ let width = match maybe_offset {
+ Some(offset) => smart_display::padded_width_of!(self.date, " ", self.time, " ", offset),
+ None => smart_display::padded_width_of!(self.date, " ", self.time),
+ };
+ Metadata::new(width, self, DateTimeMetadata { maybe_offset })
+ }
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ match metadata.maybe_offset {
+ Some(offset) => f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!("{} {} {offset}", self.date, self.time),
+ ),
+ None => f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!("{} {}", self.date, self.time),
+ ),
+ }
}
}
impl<O: MaybeOffset> fmt::Display for DateTime<O> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{} {}", self.date, self.time)?;
- if let Some(offset) = maybe_offset_as_offset_opt::<O>(self.offset) {
- write!(f, " {offset}")?;
- }
- Ok(())
+ SmartDisplay::fmt(self, f)
+ }
+}
+
+impl<O: MaybeOffset> fmt::Debug for DateTime<O> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Display::fmt(self, f)
}
}
-// region: trait impls
impl<O: MaybeOffset> PartialEq for DateTime<O> {
fn eq(&self, rhs: &Self) -> bool {
if O::HAS_LOGICAL_OFFSET {
diff --git a/vendor/time/src/ext.rs b/vendor/time/src/ext.rs
index a2acc1101..1b89d4155 100644
--- a/vendor/time/src/ext.rs
+++ b/vendor/time/src/ext.rs
@@ -220,19 +220,31 @@ impl NumericalStdDuration for u64 {
}
fn std_minutes(self) -> StdDuration {
- StdDuration::from_secs(self * Second::per(Minute) as Self)
+ StdDuration::from_secs(
+ self.checked_mul(Second::per(Minute) as Self)
+ .expect("overflow constructing `time::Duration`"),
+ )
}
fn std_hours(self) -> StdDuration {
- StdDuration::from_secs(self * Second::per(Hour) as Self)
+ StdDuration::from_secs(
+ self.checked_mul(Second::per(Hour) as Self)
+ .expect("overflow constructing `time::Duration`"),
+ )
}
fn std_days(self) -> StdDuration {
- StdDuration::from_secs(self * Second::per(Day) as Self)
+ StdDuration::from_secs(
+ self.checked_mul(Second::per(Day) as Self)
+ .expect("overflow constructing `time::Duration`"),
+ )
}
fn std_weeks(self) -> StdDuration {
- StdDuration::from_secs(self * Second::per(Week) as Self)
+ StdDuration::from_secs(
+ self.checked_mul(Second::per(Week) as Self)
+ .expect("overflow constructing `time::Duration`"),
+ )
}
}
@@ -278,3 +290,30 @@ impl NumericalStdDuration for f64 {
}
}
// endregion NumericalStdDuration
+
+// region: DigitCount
+/// A trait that indicates the formatted width of the value can be determined.
+///
+/// Note that this should not be implemented for any signed integers. This forces the caller to
+/// write the sign if desired.
+pub(crate) trait DigitCount {
+ /// The number of digits in the stringified value.
+ fn num_digits(self) -> u8;
+}
+
+/// A macro to generate implementations of `DigitCount` for unsigned integers.
+macro_rules! impl_digit_count {
+ ($($t:ty),* $(,)?) => {
+ $(impl DigitCount for $t {
+ fn num_digits(self) -> u8 {
+ match self.checked_ilog10() {
+ Some(n) => (n as u8) + 1,
+ None => 1,
+ }
+ }
+ })*
+ };
+}
+
+impl_digit_count!(u8, u16, u32);
+// endregion DigitCount
diff --git a/vendor/time/src/formatting/mod.rs b/vendor/time/src/formatting/mod.rs
index a22742236..77a52305b 100644
--- a/vendor/time/src/formatting/mod.rs
+++ b/vendor/time/src/formatting/mod.rs
@@ -2,12 +2,12 @@
pub(crate) mod formattable;
mod iso8601;
-
use core::num::NonZeroU8;
use std::io;
pub use self::formattable::Formattable;
use crate::convert::*;
+use crate::ext::DigitCount;
use crate::format_description::{modifier, Component};
use crate::{error, Date, OffsetDateTime, Time, UtcOffset};
@@ -38,33 +38,6 @@ const WEEKDAY_NAMES: [&[u8]; 7] = [
b"Sunday",
];
-// region: extension trait
-/// A trait that indicates the formatted width of the value can be determined.
-///
-/// Note that this should not be implemented for any signed integers. This forces the caller to
-/// write the sign if desired.
-pub(crate) trait DigitCount {
- /// The number of digits in the stringified value.
- fn num_digits(self) -> u8;
-}
-
-/// A macro to generate implementations of `DigitCount` for unsigned integers.
-macro_rules! impl_digit_count {
- ($($t:ty),* $(,)?) => {
- $(impl DigitCount for $t {
- fn num_digits(self) -> u8 {
- match self.checked_ilog10() {
- Some(n) => (n as u8) + 1,
- None => 1,
- }
- }
- })*
- };
-}
-
-impl_digit_count!(u8, u16, u32);
-// endregion extension trait
-
/// Write all bytes to the output, returning the number of bytes written.
pub(crate) fn write(output: &mut impl io::Write, bytes: &[u8]) -> io::Result<usize> {
output.write_all(bytes)?;
diff --git a/vendor/time/src/month.rs b/vendor/time/src/month.rs
index ea3480f00..55e53b4b8 100644
--- a/vendor/time/src/month.rs
+++ b/vendor/time/src/month.rs
@@ -4,6 +4,8 @@ use core::fmt;
use core::num::NonZeroU8;
use core::str::FromStr;
+use powerfmt::smart_display::{FormatterOptions, Metadata, SmartDisplay};
+
use self::Month::*;
use crate::error;
@@ -164,9 +166,35 @@ impl Month {
}
}
-impl fmt::Display for Month {
+mod private {
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct MonthMetadata;
+}
+use private::MonthMetadata;
+
+impl SmartDisplay for Month {
+ type Metadata = MonthMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<Self> {
+ match self {
+ January => Metadata::new(7, self, MonthMetadata),
+ February => Metadata::new(8, self, MonthMetadata),
+ March => Metadata::new(5, self, MonthMetadata),
+ April => Metadata::new(5, self, MonthMetadata),
+ May => Metadata::new(3, self, MonthMetadata),
+ June => Metadata::new(4, self, MonthMetadata),
+ July => Metadata::new(4, self, MonthMetadata),
+ August => Metadata::new(6, self, MonthMetadata),
+ September => Metadata::new(9, self, MonthMetadata),
+ October => Metadata::new(7, self, MonthMetadata),
+ November => Metadata::new(8, self, MonthMetadata),
+ December => Metadata::new(8, self, MonthMetadata),
+ }
+ }
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(match self {
+ f.pad(match self {
January => "January",
February => "February",
March => "March",
@@ -183,6 +211,12 @@ impl fmt::Display for Month {
}
}
+impl fmt::Display for Month {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ SmartDisplay::fmt(self, f)
+ }
+}
+
impl FromStr for Month {
type Err = error::InvalidVariant;
diff --git a/vendor/time/src/offset_date_time.rs b/vendor/time/src/offset_date_time.rs
index e88097fe3..79d91a61b 100644
--- a/vendor/time/src/offset_date_time.rs
+++ b/vendor/time/src/offset_date_time.rs
@@ -13,7 +13,9 @@ use std::io;
#[cfg(feature = "std")]
use std::time::SystemTime;
-use crate::date_time::offset_kind;
+use powerfmt::smart_display::{FormatterOptions, Metadata, SmartDisplay};
+
+use crate::date_time::{offset_kind, DateTimeMetadata};
#[cfg(feature = "formatting")]
use crate::formatting::Formattable;
use crate::internal_macros::{const_try, const_try_opt};
@@ -1034,9 +1036,25 @@ impl OffsetDateTime {
}
}
+impl SmartDisplay for OffsetDateTime {
+ type Metadata = DateTimeMetadata;
+
+ fn metadata(&self, f: FormatterOptions) -> Metadata<Self> {
+ self.0.metadata(f).reuse()
+ }
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ self.0.fmt_with_metadata(f, metadata.reuse())
+ }
+}
+
impl fmt::Display for OffsetDateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- self.0.fmt(f)
+ SmartDisplay::fmt(self, f)
}
}
diff --git a/vendor/time/src/parsing/iso8601.rs b/vendor/time/src/parsing/iso8601.rs
index 792c43280..048fc9584 100644
--- a/vendor/time/src/parsing/iso8601.rs
+++ b/vendor/time/src/parsing/iso8601.rs
@@ -19,6 +19,7 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
// Basic: [year]["W"][week][dayk]
// Extended: [year]["-"]["W"][week]["-"][dayk]
/// Parse a date in the basic or extended format. Reduced precision is permitted.
+ #[allow(clippy::needless_pass_by_ref_mut)] // rust-lang/rust-clippy#11620
pub(crate) fn parse_date<'a>(
parsed: &'a mut Parsed,
extended_kind: &'a mut ExtendedKind,
diff --git a/vendor/time/src/primitive_date_time.rs b/vendor/time/src/primitive_date_time.rs
index b985867d1..83a94610f 100644
--- a/vendor/time/src/primitive_date_time.rs
+++ b/vendor/time/src/primitive_date_time.rs
@@ -6,7 +6,9 @@ use core::time::Duration as StdDuration;
#[cfg(feature = "formatting")]
use std::io;
-use crate::date_time::offset_kind;
+use powerfmt::smart_display::{FormatterOptions, Metadata, SmartDisplay};
+
+use crate::date_time::{offset_kind, DateTimeMetadata};
#[cfg(feature = "formatting")]
use crate::formatting::Formattable;
use crate::internal_macros::{const_try, const_try_opt};
@@ -110,6 +112,7 @@ impl PrimitiveDateTime {
/// ```rust
/// # use time_macros::{datetime, time};
/// assert_eq!(datetime!(2019-01-01 0:00).time(), time!(0:00));
+ /// ```
pub const fn time(self) -> Time {
self.0.time()
}
@@ -806,9 +809,25 @@ impl PrimitiveDateTime {
}
}
+impl SmartDisplay for PrimitiveDateTime {
+ type Metadata = DateTimeMetadata;
+
+ fn metadata(&self, f: FormatterOptions) -> Metadata<Self> {
+ self.0.metadata(f).reuse()
+ }
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ self.0.fmt_with_metadata(f, metadata.reuse())
+ }
+}
+
impl fmt::Display for PrimitiveDateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- self.0.fmt(f)
+ SmartDisplay::fmt(self, f)
}
}
diff --git a/vendor/time/src/tests.rs b/vendor/time/src/tests.rs
index e637ba03d..2f9dbfe56 100644
--- a/vendor/time/src/tests.rs
+++ b/vendor/time/src/tests.rs
@@ -27,7 +27,7 @@
use std::num::NonZeroU8;
-use crate::formatting::DigitCount;
+use crate::ext::DigitCount;
use crate::parsing::combinator::rfc::iso8601;
use crate::parsing::shim::Integer;
use crate::{duration, parsing};
diff --git a/vendor/time/src/time.rs b/vendor/time/src/time.rs
index 74ab2a5ed..90abc01fc 100644
--- a/vendor/time/src/time.rs
+++ b/vendor/time/src/time.rs
@@ -7,6 +7,8 @@ use core::time::Duration as StdDuration;
use std::io;
use deranged::{RangedU32, RangedU8};
+use powerfmt::ext::FormatterExt;
+use powerfmt::smart_display::{self, FormatterOptions, Metadata, SmartDisplay};
use crate::convert::*;
#[cfg(feature = "formatting")]
@@ -96,7 +98,7 @@ impl PartialEq for Time {
impl PartialOrd for Time {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- self.as_u64().partial_cmp(&other.as_u64())
+ Some(self.cmp(other))
}
}
@@ -756,9 +758,24 @@ impl Time {
}
}
-impl fmt::Display for Time {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let (value, width) = match self.nanosecond() {
+mod private {
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct TimeMetadata {
+ /// How many characters wide the formatted subsecond is.
+ pub(super) subsecond_width: u8,
+ /// The value to use when formatting the subsecond. Leading zeroes will be added as
+ /// necessary.
+ pub(super) subsecond_value: u32,
+ }
+}
+use private::TimeMetadata;
+
+impl SmartDisplay for Time {
+ type Metadata = TimeMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<Self> {
+ let (subsecond_value, subsecond_width) = match self.nanosecond() {
nanos if nanos % 10 != 0 => (nanos, 9),
nanos if (nanos / 10) % 10 != 0 => (nanos / 10, 8),
nanos if (nanos / 100) % 10 != 0 => (nanos / 100, 7),
@@ -769,12 +786,48 @@ impl fmt::Display for Time {
nanos if (nanos / 10_000_000) % 10 != 0 => (nanos / 10_000_000, 2),
nanos => (nanos / 100_000_000, 1),
};
- write!(
- f,
- "{}:{:02}:{:02}.{value:0width$}",
- self.hour, self.minute, self.second,
+
+ let formatted_width = smart_display::padded_width_of!(
+ self.hour.get(),
+ ":",
+ self.minute.get() => width(2) fill('0'),
+ ":",
+ self.second.get() => width(2) fill('0'),
+ ".",
+ ) + subsecond_width;
+
+ Metadata::new(
+ formatted_width,
+ self,
+ TimeMetadata {
+ subsecond_width: subsecond_width as _,
+ subsecond_value,
+ },
)
}
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ let subsecond_width = metadata.subsecond_width as usize;
+ let subsecond_value = metadata.subsecond_value;
+
+ f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!(
+ "{}:{:02}:{:02}.{subsecond_value:0subsecond_width$}",
+ self.hour, self.minute, self.second
+ ),
+ )
+ }
+}
+
+impl fmt::Display for Time {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ SmartDisplay::fmt(self, f)
+ }
}
impl fmt::Debug for Time {
diff --git a/vendor/time/src/utc_offset.rs b/vendor/time/src/utc_offset.rs
index 86a937d7a..f4e6eaa2b 100644
--- a/vendor/time/src/utc_offset.rs
+++ b/vendor/time/src/utc_offset.rs
@@ -6,6 +6,8 @@ use core::ops::Neg;
use std::io;
use deranged::{RangedI32, RangedI8};
+use powerfmt::ext::FormatterExt;
+use powerfmt::smart_display::{self, FormatterOptions, Metadata, SmartDisplay};
use crate::convert::*;
use crate::error;
@@ -396,16 +398,50 @@ impl UtcOffset {
}
}
+mod private {
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct UtcOffsetMetadata;
+}
+use private::UtcOffsetMetadata;
+
+impl SmartDisplay for UtcOffset {
+ type Metadata = UtcOffsetMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<Self> {
+ let sign = if self.is_negative() { '-' } else { '+' };
+ let width = smart_display::padded_width_of!(
+ sign,
+ self.hours.abs() => width(2),
+ ":",
+ self.minutes.abs() => width(2),
+ ":",
+ self.seconds.abs() => width(2),
+ );
+ Metadata::new(width, self, UtcOffsetMetadata)
+ }
+
+ fn fmt_with_metadata(
+ &self,
+ f: &mut fmt::Formatter<'_>,
+ metadata: Metadata<Self>,
+ ) -> fmt::Result {
+ f.pad_with_width(
+ metadata.unpadded_width(),
+ format_args!(
+ "{}{:02}:{:02}:{:02}",
+ if self.is_negative() { '-' } else { '+' },
+ self.hours.abs(),
+ self.minutes.abs(),
+ self.seconds.abs(),
+ ),
+ )
+ }
+}
+
impl fmt::Display for UtcOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "{}{:02}:{:02}:{:02}",
- if self.is_negative() { '-' } else { '+' },
- self.hours.abs(),
- self.minutes.abs(),
- self.seconds.abs(),
- )
+ SmartDisplay::fmt(self, f)
}
}
diff --git a/vendor/time/src/weekday.rs b/vendor/time/src/weekday.rs
index 07642498d..543ecb22c 100644
--- a/vendor/time/src/weekday.rs
+++ b/vendor/time/src/weekday.rs
@@ -1,10 +1,11 @@
//! Days of the week.
-use core::fmt::{self, Display};
+use core::fmt;
use core::str::FromStr;
-use Weekday::*;
+use powerfmt::smart_display::{FormatterOptions, Metadata, SmartDisplay};
+use self::Weekday::*;
use crate::error;
/// Days of the week.
@@ -160,9 +161,30 @@ impl Weekday {
}
}
-impl Display for Weekday {
+mod private {
+ #[non_exhaustive]
+ #[derive(Debug, Clone, Copy)]
+ pub struct WeekdayMetadata;
+}
+use private::WeekdayMetadata;
+
+impl SmartDisplay for Weekday {
+ type Metadata = WeekdayMetadata;
+
+ fn metadata(&self, _: FormatterOptions) -> Metadata<'_, Self> {
+ match self {
+ Monday => Metadata::new(6, self, WeekdayMetadata),
+ Tuesday => Metadata::new(7, self, WeekdayMetadata),
+ Wednesday => Metadata::new(9, self, WeekdayMetadata),
+ Thursday => Metadata::new(8, self, WeekdayMetadata),
+ Friday => Metadata::new(6, self, WeekdayMetadata),
+ Saturday => Metadata::new(8, self, WeekdayMetadata),
+ Sunday => Metadata::new(6, self, WeekdayMetadata),
+ }
+ }
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(match self {
+ f.pad(match self {
Monday => "Monday",
Tuesday => "Tuesday",
Wednesday => "Wednesday",
@@ -174,6 +196,12 @@ impl Display for Weekday {
}
}
+impl fmt::Display for Weekday {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ SmartDisplay::fmt(self, f)
+ }
+}
+
impl FromStr for Weekday {
type Err = error::InvalidVariant;