-
-
Save s-celles/2a18581aa871966e749e29219264dd3c to your computer and use it in GitHub Desktop.
AIRAC dates generator - enumerates AIRAC cycles: previous, current and next.
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 Out-AIRACCycles | |
{ | |
Param ( [DateTime] $currentDay = ( Get-Date ) | |
, [DateTime] $initialDay = ( Get-Date -Year 2015 -Month 1 -Day 8 ) | |
, $interval = 28 | |
, $culture = [System.Globalization.CultureInfo]::GetCultureInfo("en-US") ) | |
$offset = (New-TimeSpan -Start $initialDay -End ( Get-Date -Year ( $currentDay.Year - 1 ) -Month 1 -Day 1 ) ).Days | |
$offset .. ( $offset + 365 * 3 ) | | |
? { $_ % 28 -eq 0 } | | |
select @{ N="date"; E={ $initialDay.AddDays( $_ ) } } | | |
select -expand date | | |
group Year | | |
% { | |
$year = $_.Name | |
$dates = $_.Group | |
1 .. $_.Count | select @{ N="Cycle"; E={ $_ } }, | |
@{ N="Ident"; E={ "$($year.Substring(2,2))$($_.ToString().PadLeft(2, '0' ) )" } }, | |
@{ N="EffectiveDate"; E={ Get-Date $dates[ $_-1 ] -Format d } }, | |
@{ N="AIRAC"; E={ $dates[ $_-1 ].ToString("dd MMM yy", $culture).ToUpperInvariant() } }, | |
@{ N="distance"; E={ ( New-TimeSpan -Start $currentDay -End $dates[ $_-1 ] ).Days } } | |
} | | |
? { [Math]::Abs( $_.distance ) -lt $interval * 2 } | | |
select Cycle, Ident, EffectiveDate, AIRAC -First 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment