Skip to content

Commit

Permalink
move assume_local
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Sep 17, 2023
1 parent 578f559 commit 7d8f2ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
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
10 changes: 7 additions & 3 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.
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

0 comments on commit 7d8f2ca

Please sign in to comment.