Skip to content

Instantly share code, notes, and snippets.

@fatherjack
Last active December 12, 2018 14:14
Show Gist options
  • Save fatherjack/68e0ab0699a9a1e28b05aa19a9664109 to your computer and use it in GitHub Desktop.
Save fatherjack/68e0ab0699a9a1e28b05aa19a9664109 to your computer and use it in GitHub Desktop.
Function TimeToSanta {
<#
.Synopsis
Show how long you have to wait to open your presents
.DESCRIPTION
Be able to leave your shopping to the very last minute with this state-of-the-art function to show
how long is left to 25th Dec 09:00. Two variations exist depending on whether the information is to be shown
at the console prompt or as a message
.EXAMPLE
TimeToSanta -purpose console
This method returns a string that is a longer message
.EXAMPLE
TimeToSanta -purpose prompt
This method returns a string small enough to give a countdown in your console prompt
#>
param(
# This value is the decide if the output is for the commandline prompt or a console message
[Parameter()]
[ValidateSet("console", "prompt")]
[string]
$Purpose
)
# we need 'this year' and the day number of Christmas Day ...
$Year = (get-date).Year
$DOY = ([datetime]"25-dec-$year").DayOfYear
# ... so that we can add a year on to Christmas Day if we are between 25th Dec and 1st Jan
if ((get-date).DayOfYear -gt $DOY) {
$Year ++
}
# ... so that we get the gap to a future 25th Dec
$CDay = [datetime]"25-Dec-$Year 09:00:00"
# TTS is a duration between two dates
$TimeToSanta = New-TimeSpan -Start (get-date) -End $CDay
# Construct the output string according to requirement of calling process
switch ($Purpose) {
"console" {$msg = "Christmas Day in $($TimeToSanta.Days) Days $($TimeToSanta.hours) hours $($TimeToSanta.Minutes) Minutes"}
"prompt" {$msg = "$($TimeToSanta.Days) days $(($TimeToSanta.Hours).tostring(00)):$(($TimeToSanta.Minutes).tostring(00)):$(($TimeToSanta.Seconds).tostring(00))"}
}
return ($msg)
}
<#
Edit your Prompt with the code below to have updates every time you run a command from your console
if ((get-date).Month -eq 12 -and (get-date).Day -lt 25) {
Write-Host $msg -NoNewline
$msg = "["
$msg += TimetoSanta -purpose Prompt
$msg += "]"
Write-Host $msg -NoNewline -BackgroundColor Red -ForegroundColor DarkBlue
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment