Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_identity"
version = "0.16.1"
version = "0.16.2"
description = "Rust wrappers around Microsoft Azure REST APIs - Azure identity helper crate"
readme = "README.md"
authors = ["Microsoft Corp."]
Expand Down
45 changes: 44 additions & 1 deletion sdk/identity/src/token_credentials/azure_cli_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,25 @@ mod az_cli_date_format {
};

let as_unix = as_utc.unix_timestamp();

// if we can't find the local time type, just return the UTC date
let Ok(local_time_type) = tz.find_local_time_type(as_unix) else {
return as_utc;
};

// if we can't convert the unix timestamp to a DateTime, just return the UTC date
let Ok(date) = tz::DateTime::from_timespec(as_unix, 0, tz.as_ref()) else {
let date = as_utc.date();
let time = as_utc.time();
let Ok(date) = tz::DateTime::new(
date.year(),
u8::from(date.month()),
date.day(),
time.hour(),
time.minute(),
time.second(),
time.nanosecond(),
*local_time_type,
) else {
return as_utc;
};

Expand Down Expand Up @@ -174,6 +191,32 @@ mod tests {
az_cli_date_format::parse(expires_on)?,
az_cli_date_format::assume_local(&datetime!(2022-07-30 12:12:53.919110))
);

Ok(())
}

#[cfg(unix)]
#[test]
/// test the timezone conversion works as expected on unix platforms
///
/// To validate the timezone conversion works as expected, this test
/// temporarily sets the timezone to PST, performs the check, then resets
/// the TZ enviornment variable.
fn check_timezone() -> azure_core::Result<()> {
let before = std::env::var("TZ").ok();
std::env::set_var("TZ", "PST");
let expires_on = "2022-07-30 12:12:53.919110";
let result = az_cli_date_format::parse(expires_on);

if let Some(before) = before {
std::env::set_var("TZ", before);
} else {
std::env::remove_var("TZ");
}

let expected = datetime!(2022-07-30 16:12:53).assume_utc();
assert_eq!(expected, result?);

Ok(())
}
}