Skip to content

Commit

Permalink
✨ Expand numeric type beyond int when needed for Epoch value
Browse files Browse the repository at this point in the history
  • Loading branch information
brianary committed Jan 7, 2024
1 parent e7d0602 commit 1cf8ab7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ConvertTo-EpochTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ Get-Date |ConvertTo-EpochTime.ps1
# Indicates the DateTime provided is local, and should be converted to UTC.
[Alias('UTC','Z')][switch] $UniversalTime
)
Process{[int][double]::Parse((Get-Date $(if($UniversalTime){$DateTime.ToUniversalTime()}else{$DateTime}) -UFormat %s))}
Process
{
$value = [double]::Parse((Get-Date $(if($UniversalTime){$DateTime.ToUniversalTime()}else{$DateTime}) -UFormat %s))
if($value -le [int]::MaxValue -and $value -ge [int]::MinValue) {return [int]$value}
if($value -le [long]::MaxValue -and $value -ge [long]::MinValue) {return [long]$value}
return $value
}

0 comments on commit 1cf8ab7

Please sign in to comment.