From cb33d3852aef6369c914eef73d050fd03c2d5889 Mon Sep 17 00:00:00 2001 From: Niko Martini Date: Thu, 15 Aug 2019 11:28:18 +0200 Subject: [PATCH] WIP --- lib/core/tools/ConvertTo-Seconds.psm1 | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/core/tools/ConvertTo-Seconds.psm1 b/lib/core/tools/ConvertTo-Seconds.psm1 index afb3a22..85e7f41 100644 --- a/lib/core/tools/ConvertTo-Seconds.psm1 +++ b/lib/core/tools/ConvertTo-Seconds.psm1 @@ -3,19 +3,26 @@ function ConvertTo-Seconds() { param( - [single]$Value, - [string]$Unit + [string]$Value, + [char]$Unit, + [switch]$Milliseconds ); - 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; } + #100 D + #100 D + $Unit = $Value.Substring($Value.get_Length()-2)[0]; + [single]$ValueSplitted = $Value; + #$Name.Substring($Name.get_Length()-1); + #$Name.Substring(0,$Name.get_Length()-1); + switch ([int][char]$Unit) { +# { 'ms', 'milliseconds' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } + { 115 -contains $_ } { $result = $ValueSplitted; $boolOption = $true; } + { 109 -contains $_ } { $result = ($ValueSplitted * 60); $boolOption = $true; } + { 104 -contains $_ } { $result = ($ValueSplitted * 3600); $boolOption = $true; } + { 100 -contains $_ } { $result = ($ValueSplitted * 86400); $boolOption = $true; } + { 87 -contains $_ } { $result = ($ValueSplitted * 604800); $boolOption = $true; } + { 77 -contains $_ } { $result = ($ValueSplitted * (2.5[math]::Pow(10, 6))); $boolOption = $true; } + { 89 -contains $_ } { $result = ($ValueSplitted * (3.10[math]::Pow(10, 7))); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input';