Skip to content

Commit

Permalink
Merge pull request #11 from tjgruber/10-datetime-isnt-locale-safe
Browse files Browse the repository at this point in the history
10 datetime isnt locale safe
  • Loading branch information
tjgruber authored Nov 16, 2024
2 parents 002878c + 9e0a395 commit 9410978
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Private/Invoke-AzureStorageBlobUpload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,21 @@ function Invoke-AzureStorageBlobUpload {
for ($Chunk = 0; $Chunk -lt $ChunkCount; $Chunk++) {
Write-Verbose -Message "SAS Uri renewal timer has elapsed for: $($SASRenewalTimer.Elapsed.Minutes) minute $($SASRenewalTimer.Elapsed.Seconds) seconds"

# Refresh access token if about to expire
$UTCDateTime = (Get-Date).ToUniversalTime()
# Convert ExpiresOn to DateTimeOffset in UTC
$ExpiresOnUTC = [DateTimeOffset]::Parse(
$Global:AccessToken.ExpiresOn.ToString(),
[System.Globalization.CultureInfo]::InvariantCulture,
[System.Globalization.DateTimeStyles]::AssumeUniversal
).ToUniversalTime()

# Determine the token expiration count as minutes
$TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime() - $UTCDateTime).TotalMinutes)
# Get the current UTC time as DateTimeOffset
$UTCDateTime = [DateTimeOffset]::UtcNow

# Calculate the TimeSpan between expiration and current time
$TimeSpan = $ExpiresOnUTC - $UTCDateTime

# Calculate the token expiration time in minutes
$TokenExpireMinutes = [System.Math]::Round($TimeSpan.TotalMinutes)

# Determine if refresh of access token is required when expiration count is less than or equal to minimum age
if ($TokenExpireMinutes -le 10) {
Expand Down

0 comments on commit 9410978

Please sign in to comment.