summaryrefslogtreecommitdiffstats
path: root/vendor/time/src/parsing
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /vendor/time/src/parsing
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src/parsing')
-rw-r--r--vendor/time/src/parsing/component.rs13
-rw-r--r--vendor/time/src/parsing/iso8601.rs24
-rw-r--r--vendor/time/src/parsing/parsed.rs6
3 files changed, 28 insertions, 15 deletions
diff --git a/vendor/time/src/parsing/component.rs b/vendor/time/src/parsing/component.rs
index e7b852706..23035893e 100644
--- a/vendor/time/src/parsing/component.rs
+++ b/vendor/time/src/parsing/component.rs
@@ -2,6 +2,7 @@
use core::num::{NonZeroU16, NonZeroU8};
+use crate::convert::*;
use crate::format_description::modifier;
#[cfg(feature = "large-dates")]
use crate::parsing::combinator::n_to_m_digits_padded;
@@ -315,14 +316,12 @@ pub(crate) fn parse_unix_timestamp(
let ParsedItem(input, sign) = opt(sign)(input);
let ParsedItem(input, nano_timestamp) = match modifiers.precision {
modifier::UnixTimestampPrecision::Second => {
- n_to_m_digits::<1, 14, u128>(input)?.map(|val| val * 1_000_000_000)
- }
- modifier::UnixTimestampPrecision::Millisecond => {
- n_to_m_digits::<1, 17, u128>(input)?.map(|val| val * 1_000_000)
- }
- modifier::UnixTimestampPrecision::Microsecond => {
- n_to_m_digits::<1, 20, u128>(input)?.map(|val| val * 1_000)
+ n_to_m_digits::<1, 14, u128>(input)?.map(|val| val * Nanosecond.per(Second) as u128)
}
+ modifier::UnixTimestampPrecision::Millisecond => n_to_m_digits::<1, 17, u128>(input)?
+ .map(|val| val * Nanosecond.per(Millisecond) as u128),
+ modifier::UnixTimestampPrecision::Microsecond => n_to_m_digits::<1, 20, u128>(input)?
+ .map(|val| val * Nanosecond.per(Microsecond) as u128),
modifier::UnixTimestampPrecision::Nanosecond => n_to_m_digits::<1, 23, _>(input)?,
};
diff --git a/vendor/time/src/parsing/iso8601.rs b/vendor/time/src/parsing/iso8601.rs
index 21c89bab3..1afee4e31 100644
--- a/vendor/time/src/parsing/iso8601.rs
+++ b/vendor/time/src/parsing/iso8601.rs
@@ -1,5 +1,6 @@
//! Parse parts of an ISO 8601-formatted value.
+use crate::convert::*;
use crate::error;
use crate::error::ParseFromDescription::{InvalidComponent, InvalidLiteral};
use crate::format_description::well_known::iso8601::EncodedConfig;
@@ -124,12 +125,16 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
*parsed = parsed
.with_hour_24(hour)
.ok_or(InvalidComponent("hour"))?
- .with_minute((fractional_part * 60.0) as _)
+ .with_minute((fractional_part * Second.per(Minute) as f64) as _)
.ok_or(InvalidComponent("minute"))?
- .with_second((fractional_part * 3600.0 % 60.) as _)
+ .with_second(
+ (fractional_part * Second.per(Hour) as f64 % Minute.per(Hour) as f64)
+ as _,
+ )
.ok_or(InvalidComponent("second"))?
.with_subsecond(
- (fractional_part * 3_600. * 1_000_000_000. % 1_000_000_000.) as _,
+ (fractional_part * Nanosecond.per(Hour) as f64
+ % Nanosecond.per(Second) as f64) as _,
)
.ok_or(InvalidComponent("subsecond"))?;
return Ok(input);
@@ -157,10 +162,11 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
*parsed = parsed
.with_minute(minute)
.ok_or(InvalidComponent("minute"))?
- .with_second((fractional_part * 60.) as _)
+ .with_second((fractional_part * Second.per(Minute) as f64) as _)
.ok_or(InvalidComponent("second"))?
.with_subsecond(
- (fractional_part * 60. * 1_000_000_000. % 1_000_000_000.) as _,
+ (fractional_part * Nanosecond.per(Minute) as f64
+ % Nanosecond.per(Second) as f64) as _,
)
.ok_or(InvalidComponent("subsecond"))?;
return Ok(input);
@@ -200,9 +206,11 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
let (input, second, subsecond) = match float(input) {
Some(ParsedItem(input, (second, None))) => (input, second, 0),
- Some(ParsedItem(input, (second, Some(fractional_part)))) => {
- (input, second, round(fractional_part * 1_000_000_000.) as _)
- }
+ Some(ParsedItem(input, (second, Some(fractional_part)))) => (
+ input,
+ second,
+ round(fractional_part * Nanosecond.per(Second) as f64) as _,
+ ),
None if extended_kind.is_extended() => {
return Err(error::Parse::ParseFromDescription(InvalidComponent(
"second",
diff --git a/vendor/time/src/parsing/parsed.rs b/vendor/time/src/parsing/parsed.rs
index 26405cb11..04c74a720 100644
--- a/vendor/time/src/parsing/parsed.rs
+++ b/vendor/time/src/parsing/parsed.rs
@@ -423,6 +423,7 @@ impl Parsed {
}
/// Obtain the absolute value of the offset minute.
+ #[doc(hidden)]
#[deprecated(since = "0.3.8", note = "use `parsed.offset_minute_signed()` instead")]
pub const fn offset_minute(&self) -> Option<u8> {
Some(const_try_opt!(self.offset_minute_signed()).unsigned_abs())
@@ -447,6 +448,7 @@ impl Parsed {
}
/// Obtain the absolute value of the offset second.
+ #[doc(hidden)]
#[deprecated(since = "0.3.8", note = "use `parsed.offset_second_signed()` instead")]
pub const fn offset_second(&self) -> Option<u8> {
Some(const_try_opt!(self.offset_second_signed()).unsigned_abs())
@@ -523,6 +525,7 @@ impl Parsed {
}
/// Set the named component.
+ #[doc(hidden)]
#[deprecated(
since = "0.3.8",
note = "use `parsed.set_offset_minute_signed()` instead"
@@ -543,6 +546,7 @@ impl Parsed {
}
/// Set the named component.
+ #[doc(hidden)]
#[deprecated(
since = "0.3.8",
note = "use `parsed.set_offset_second_signed()` instead"
@@ -615,6 +619,7 @@ impl Parsed {
}
/// Set the named component and return `self`.
+ #[doc(hidden)]
#[deprecated(
since = "0.3.8",
note = "use `parsed.with_offset_minute_signed()` instead"
@@ -635,6 +640,7 @@ impl Parsed {
}
/// Set the named component and return `self`.
+ #[doc(hidden)]
#[deprecated(
since = "0.3.8",
note = "use `parsed.with_offset_second_signed()` instead"