Utils/sleep.ps1
|
Register-GnuUtil @{ Name = 'sleep' Category = 'Shell helpers' Synopsis = 'Delay for a specified amount of time.' Usage = @('sleep NUMBER[SUFFIX]...', 'sleep OPTION') Description = @( 'Pause for NUMBER seconds. SUFFIX may be ''s'' for seconds (the default),', '''m'' for minutes, ''h'' for hours or ''d'' for days. NUMBER need not be an', 'integer. Given two or more arguments, pause for the amount of time', 'specified by the sum of their values. ''infinity'' sleeps forever.' ) } function script:ConvertFrom-GnuSleepInterval { <# .SYNOPSIS Parses NUMBER[smhd] (or inf/infinity) into seconds. Returns nothing if the text is invalid. #> param([Parameter(Mandatory)][AllowEmptyString()][string]$Text) if ($Text -notmatch '^(?<number>(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?|inf|infinity)(?<unit>[smhd]?)$') { return } $number = $Matches['number'] if ($number -like 'inf*') { return [double]::PositiveInfinity } $value = [double]::Parse($number, [System.Globalization.CultureInfo]::InvariantCulture) switch ($Matches['unit']) { 'm' { $value *= 60 } 'h' { $value *= 3600 } 'd' { $value *= 86400 } } $value } |