Get French Holidays

by Aug 24, 2023

I saw this blog post and I decided to publish this one for France. Here is a PowerShell function that gets all French holidays:

function Get-FrenchHoliday
{
    param
    (
        [int]
        $Year = (Get-Date).Year,

        [ValidateSet("alsace-moselle", "guadeloupe", "guyane", "la-reunion", "martinique", "mayotte", "metropole", "nouvelle-caledonie", "polynesie-francaise", "saint-barthelemy", "saint-martin", "saint-pierre-et-miquelon", "wallis-et-futuna")]
        [string]
        $Area = 'metropole',

        [switch]
        $NextOnly
    )

    $url = "https://calendrier.api.gouv.fr/jours-feries/$Area/$Year.json"

    $holidays = Invoke-RestMethod -Uri $url -UseBasicParsing

    foreach ($obj in $holidays.PSObject.Properties) {
        if (-Not ($NextOnly.IsPresent) -or (((([DateTime]$obj.Name).Ticks) - (Get-Date).Ticks) -gt 0)) {
            Write-Host "$($obj.Value) : $($obj.Name)"
        }
    }
}

Run the function above, then either run the command as-is:

Get-FrenchHoliday

Get-FrenchHoliday

Or, submit additional arguments to get specific holidays for a specific area:

Get-FrenchHoliday

Get-FrenchHoliday with parameters

Get-FrenchHoliday with parameters

Thanks to this function, my co-worker Tim will always know when I have a public holiday! 😉