From 8f16291fb5c5b54b297b29c25d70445da5185f45 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 1 Jun 2021 16:20:45 +0200 Subject: [PATCH] Fixes exception on time conversion --- doc/31-Changelog.md | 1 + lib/core/tools/ConvertFrom-TimeSpan.psm1 | 4 ++++ lib/core/tools/ConvertTo-Seconds.psm1 | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index dd54b22..a05050c 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -33,6 +33,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#245](https://github.com/Icinga/icinga-powershell-framework/pull/245) Fixes loading of `.pfx` certificates by properly checking the file type * [#265](https://github.com/Icinga/icinga-powershell-framework/pull/265) Fixes `Test-Numeric` to now accept negative numeric values and als fixes errors, causing `.` to be allowed multiple times. `ConvertFrom-TimeSpan` now properly prints on negative values if the time provided is positive or negative and also prints microseconds as `us` in case the value is loer than `1ms` * [#269](https://github.com/Icinga/icinga-powershell-framework/pull/269) Fixes unhandled exception on `Set-IcingaCacheData`, as the `-ErrorAction Stop` argument was not set and therefor the function never halted on errors +* [#272](https://github.com/Icinga/icinga-powershell-framework/pull/272) Fixes invalid unit conversion, in case first char of a string is matching time metrics ## 1.4.1 (2021-03-10) diff --git a/lib/core/tools/ConvertFrom-TimeSpan.psm1 b/lib/core/tools/ConvertFrom-TimeSpan.psm1 index 7b95214..fd52b9c 100644 --- a/lib/core/tools/ConvertFrom-TimeSpan.psm1 +++ b/lib/core/tools/ConvertFrom-TimeSpan.psm1 @@ -16,6 +16,10 @@ function ConvertFrom-TimeSpan() $Sign = '-'; } + if ((Test-Numeric $Seconds) -eq $FALSE) { + return $Seconds; + } + $TimeSpan = [TimeSpan]::FromSeconds($Seconds); if ($TimeSpan.TotalDays -ge 1.0) { diff --git a/lib/core/tools/ConvertTo-Seconds.psm1 b/lib/core/tools/ConvertTo-Seconds.psm1 index 1b423cb..0114015 100644 --- a/lib/core/tools/ConvertTo-Seconds.psm1 +++ b/lib/core/tools/ConvertTo-Seconds.psm1 @@ -71,7 +71,7 @@ function ConvertTo-Seconds() $result = ($ValueSplitted / [math]::Pow(10, 3)); } else { if ($UnitPart.Length -gt 1) { - Throw $errorMsg; + return $Value; } switch ([int][char]$UnitPart) {