Last active
January 1, 2020 14:08
-
-
Save fatherjack/35a53f5a409db2e518d789e42285db3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function TimeToSQLBits { | |
<# | |
.Synopsis | |
Show how long you have to wait for the biggest data conference in Europe | |
.DESCRIPTION | |
Make sure you get prepared for the next SQLBits conference. | |
.EXAMPLE | |
TimeToSQLBits -purpose console | |
This method returns a string that is a longer message | |
.EXAMPLE | |
TimeToSQLBits -purpose prompt | |
This method returns a string small enough to give a countdown in your console prompt | |
.NOTES | |
01-Jan-2020 : Edit - updated for SQLBits 2020 | |
#> | |
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 SQLBits ... | |
$Year = (Get-Date).Year | |
$DOY = ([datetime]"31-Mar-$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 date | |
$CDay = [datetime]"31-Mar-$Year 09:00:00" | |
# TTS is a duration between two dates | |
$TimeToSQLBits = New-TimeSpan -Start (Get-Date) -End $CDay | |
# Construct the output string according to requirement of calling process | |
switch ($Purpose) { | |
"console" { $msg = "SQLBits starts in {0} Days {1:hh} hours {1:mm} Minutes" -f $($TimeToSQLBits.Days), $TimeToSQLBits } | |
"prompt" { $msg = "{0} days {1:hh}:{1:mm}:{1:ss}" -f $($TimeToSQLBits.Days), $TimeToSQLBits } | |
} | |
return ($msg) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment