mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Toolset for conversion
This commit is contained in:
parent
839e012643
commit
54499cae4c
1 changed files with 27 additions and 0 deletions
27
lib/core/tools/ConvertTo-Seconds.psm1
Normal file
27
lib/core/tools/ConvertTo-Seconds.psm1
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue