Skip to content

Commit

Permalink
remove local-offset feature from time in azure_core (#1391)
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Sep 19, 2023
1 parent a9bdf2e commit 026bdf6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ url = "2.2"
uuid = { version = "1.0" }
pin-project = "1.0"
paste = "1.0"
time = { version = "0.3.10", features = ["serde-well-known", "macros", "local-offset"] }
time = { version = "0.3.10", features = ["serde-well-known", "macros"] }
tokio = {version="1.0", optional=true}

# When target is `wasm32`, include `getrandom` and enable `wasm-bindgen` feature in `time`.
Expand Down
5 changes: 0 additions & 5 deletions sdk/core/src/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ pub fn to_last_state_change(date: &OffsetDateTime) -> String {
date.format(LAST_STATE_CHANGE_FORMAT).unwrap()
}

/// Assumes the local offset. Default to UTC if unable to get local offset.
pub fn assume_local(date: &PrimitiveDateTime) -> OffsetDateTime {
date.assume_offset(UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC))
}

// Create a duration from the number of minutes.
pub fn duration_from_minutes(minutes: u64) -> Duration {
Duration::from_secs(minutes * 60)
Expand Down
13 changes: 8 additions & 5 deletions sdk/identity/src/token_credentials/azure_cli_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use std::str;
use time::OffsetDateTime;

mod az_cli_date_format {
use azure_core::date;
use azure_core::error::{ErrorKind, ResultExt};
use serde::{self, Deserialize, Deserializer};
use time::format_description::FormatItem;
use time::macros::format_description;
use time::{OffsetDateTime, PrimitiveDateTime};
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};

const FORMAT: &[FormatItem] =
format_description!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:6]");
Expand All @@ -22,7 +21,12 @@ mod az_cli_date_format {
.with_context(ErrorKind::DataConversion, || {
format!("unable to parse expiresOn '{s}")
})?;
Ok(date::assume_local(&dt))
Ok(assume_local(&dt))
}

/// Assumes the local offset. Default to UTC if unable to get local offset.
pub(crate) fn assume_local(date: &PrimitiveDateTime) -> OffsetDateTime {
date.assume_offset(UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC))
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<OffsetDateTime, D::Error>
Expand Down Expand Up @@ -131,15 +135,14 @@ impl TokenCredential for AzureCliCredential {
#[cfg(test)]
mod tests {
use super::*;
use azure_core::date;
use time::macros::datetime;

#[test]
fn can_parse_expires_on() -> azure_core::Result<()> {
let expires_on = "2022-07-30 12:12:53.919110";
assert_eq!(
az_cli_date_format::parse(expires_on)?,
date::assume_local(&datetime!(2022-07-30 12:12:53.919110))
az_cli_date_format::assume_local(&datetime!(2022-07-30 12:12:53.919110))
);
Ok(())
}
Expand Down

0 comments on commit 026bdf6

Please sign in to comment.