From dac21673c1d84a017ac965649a8aeffffe75db89 Mon Sep 17 00:00:00 2001 From: Niko Martini Date: Thu, 25 Jul 2019 18:16:33 +0200 Subject: [PATCH] Toolset for conversion --- lib/core/tools/ConvertTo-Seconds.psm1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/core/tools/ConvertTo-Seconds.psm1 diff --git a/lib/core/tools/ConvertTo-Seconds.psm1 b/lib/core/tools/ConvertTo-Seconds.psm1 new file mode 100644 index 0000000..afb3a22 --- /dev/null +++ b/lib/core/tools/ConvertTo-Seconds.psm1 @@ -0,0 +1,27 @@ +# year month week days hours minutes seconds milliseconds + +function ConvertTo-Seconds() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + { 'ms', 'milliseconds' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 's', 'seconds' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'm', 'minutes' -contains $_ } { $result = ($Value * 60); $boolOption = $true; } + { 'h', 'hours' -contains $_ } { $result = ($Value * 3600); $boolOption = $true; } + { 'd', 'day' -contains $_ } { $result = ($Value * 86400); $boolOption = $true; } + { 'W', 'Week' -contains $_ } { $result = ($Value * 604800); $boolOption = $true; } + { 'M', 'Month' -contains $_ } { $result = ($Value * [math]::Pow(2.628, 6)); $boolOption = $true; } + { 'Y', 'Year' -contains $_ } { $result = ($Value * [math]::Pow(10, 7)); $boolOption = $true; } + default { + if (-Not $boolOption) { + Throw 'Invalid input'; + } + } + } + + return $result; +} \ No newline at end of file