mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-20 08:58:18 +02:00
Improve check-midnight.ps1, check-noon.ps1, and check-tea-time.ps1
This commit is contained in:
parent
394cab03a1
commit
3868e56a70
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks the time until Midnight
|
Checks for Midnight
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This script checks the time until Midnight and replies by text-to-speech (TTS).
|
This script checks the time until Midnight and replies by text-to-speech (TTS).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -11,16 +11,27 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function TimeSpanToString { param([TimeSpan]$Delta)
|
||||||
|
$Result = ""
|
||||||
|
if ($Delta.Hours -eq 1) { $Result += "1 hour, "
|
||||||
|
} elseif ($Delta.Hours -gt 1) { $Result += "$($Delta.Hours) hours, "
|
||||||
|
}
|
||||||
|
if ($Delta.Minutes -eq 1) { $Result += "1 minute"
|
||||||
|
} else { $Result += "$($Delta.Minutes) minutes"
|
||||||
|
}
|
||||||
|
return $Result
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Now = [DateTime]::Now
|
$Now = [DateTime]::Now
|
||||||
if ($Now.Hour -lt 12) {
|
if ($Now.Hour -lt 12) {
|
||||||
$Midnight = Get-Date -Hour 0 -Minute 0 -Second 0
|
$Midnight = Get-Date -Hour 0 -Minute 0 -Second 0
|
||||||
$Delta = $Now - $Midnight
|
$TimeSpan = TimeSpanToString($Now - $Midnight)
|
||||||
$Reply = "Midnight was $($Delta.Hours) hours, $($Delta.Minutes) minutes ago."
|
$Reply = "Midnight was $TimeSpan ago."
|
||||||
} else {
|
} else {
|
||||||
$Midnight = Get-Date -Hour 23 -Minute 59 -Second 59
|
$Midnight = Get-Date -Hour 23 -Minute 59 -Second 59
|
||||||
$Delta = $Midnight - $Now
|
$TimeSpan = TimeSpanToString($Midnight - $Now)
|
||||||
$Reply = "Midnight is in $($Delta.Hours) hours, $($Delta.Minutes) minutes."
|
$Reply = "Midnight is in $TimeSpan."
|
||||||
}
|
}
|
||||||
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks the time until Noon
|
Checks for Noon
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This script checks the time until Noon and replies by text-to-speech (TTS).
|
This script checks the time until Noon and replies by text-to-speech (TTS).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -11,15 +11,26 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function TimeSpanToString { param([TimeSpan]$Delta)
|
||||||
|
$Result = ""
|
||||||
|
if ($Delta.Hours -eq 1) { $Result += "1 hour, "
|
||||||
|
} elseif ($Delta.Hours -gt 1) { $Result += "$($Delta.Hours) hours, "
|
||||||
|
}
|
||||||
|
if ($Delta.Minutes -eq 1) { $Result += "1 minute"
|
||||||
|
} else { $Result += "$($Delta.Minutes) minutes"
|
||||||
|
}
|
||||||
|
return $Result
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Now = [DateTime]::Now
|
$Now = [DateTime]::Now
|
||||||
$Noon = Get-Date -Hour 12 -Minute 0 -Second 0
|
$Noon = Get-Date -Hour 12 -Minute 0 -Second 0
|
||||||
if ($Now -lt $Noon) {
|
if ($Now -lt $Noon) {
|
||||||
$Delta = $Noon - $Now
|
$TimeSpan = TimeSpanToString($Noon - $Now)
|
||||||
$Reply = "Noon is in $($Delta.Hours) hours, $($Delta.Minutes) minutes."
|
$Reply = "Noon is in $TimeSpan."
|
||||||
} else {
|
} else {
|
||||||
$Delta = $Now - $Noon
|
$TimeSpan = TimeSpanToString($Now - $Noon)
|
||||||
$Reply = "Noon was $($Delta.Hours) hours, $($Delta.Minutes) minutes ago."
|
$Reply = "Noon was $TimeSpan ago."
|
||||||
}
|
}
|
||||||
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks the time until Tea time
|
Checks for Tea time
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This script checks the time until Tea time and replies by text-to-speech (TTS).
|
This script checks the time until Tea time and replies by text-to-speech (TTS).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -11,15 +11,26 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function TimeSpanToString { param([TimeSpan]$Delta)
|
||||||
|
$Result = ""
|
||||||
|
if ($Delta.Hours -eq 1) { $Result += "1 hour, "
|
||||||
|
} elseif ($Delta.Hours -gt 1) { $Result += "$($Delta.Hours) hours, "
|
||||||
|
}
|
||||||
|
if ($Delta.Minutes -eq 1) { $Result += "1 minute"
|
||||||
|
} else { $Result += "$($Delta.Minutes) minutes"
|
||||||
|
}
|
||||||
|
return $Result
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Now = [DateTime]::Now
|
$Now = [DateTime]::Now
|
||||||
$TeaTime = Get-Date -Hour 16 -Minute 0 -Second 0
|
$TeaTime = Get-Date -Hour 16 -Minute 0 -Second 0
|
||||||
if ($Now -lt $TeaTime) {
|
if ($Now -lt $TeaTime) {
|
||||||
$Delta = $TeaTime - $Now
|
$TimeSpan = TimeSpanToString($TeaTime - $Now)
|
||||||
$Reply = "Tea time is in $($Delta.Hours) hours, $($Delta.Minutes) minutes."
|
$Reply = "Tea time is in $TimeSpan."
|
||||||
} else {
|
} else {
|
||||||
$Delta = $Now - $TeaTime
|
$TimeSpan = TimeSpanToString($Now - $TeaTime)
|
||||||
$Reply = "Tea time was $($Delta.Hours) hours, $($Delta.Minutes) minutes ago."
|
$Reply = "Tea time was $TimeSpan ago."
|
||||||
}
|
}
|
||||||
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
Loading…
Reference in New Issue
Block a user