Skip to content

Instantly share code, notes, and snippets.

@a4099181
Last active February 5, 2021 08:06
Show Gist options
  • Save a4099181/2fbc4c98d560e7ec0400d8dce2da1201 to your computer and use it in GitHub Desktop.
Save a4099181/2fbc4c98d560e7ec0400d8dce2da1201 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
}
@a4099181
Copy link
Author

a4099181 commented Apr 1, 2017

Usage samples

No arguments, no pipes. It outputs AIRAC cycles for today.

PS >Out-AIRACCycles

Cycle Ident EffectiveDate AIRAC    
----- ----- ------------- -----    
    3 1703  02.03.2017    02 MAR 17
    4 1704  30.03.2017    30 MAR 17
    5 1705  27.04.2017    27 APR 17

Specific date (i.e.: 5th january 2020):

PS >Out-AIRACCycles -currentDay ( Get-Date -Year 2020 -Month 1 -Day 5 )

Cycle Ident EffectiveDate AIRAC    
----- ----- ------------- -----    
   13 1913  05.12.2019    05 DEC 19
    1 2001  02.01.2020    02 JAN 20
    2 2002  30.01.2020    30 JAN 20

Only current cycle:

PS >Out-AIRACCycles | select -Index 1

Cycle Ident EffectiveDate AIRAC    
----- ----- ------------- -----    
    4 1704  30.03.2017    30 MAR 17

Only next cycle:

PS >Out-AIRACCycles | select -Index 2

Cycle Ident EffectiveDate AIRAC    
----- ----- ------------- -----    
    5 1705  27.04.2017    27 APR 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment