Skip to content

Instantly share code, notes, and snippets.

@scls19fr
Forked from a4099181/Out-AIRACCycles.ps1
Created February 5, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scls19fr/2a18581aa871966e749e29219264dd3c to your computer and use it in GitHub Desktop.
Save scls19fr/2a18581aa871966e749e29219264dd3c to your computer and use it in GitHub Desktop.
AIRAC dates generator - enumerates AIRAC cycles: previous, current and next.
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