Skip to content

Instantly share code, notes, and snippets.

@pkese
Last active November 13, 2023 17:40
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 pkese/df4a7cc9b972c971041def5b6fe591ce to your computer and use it in GitHub Desktop.
Save pkese/df4a7cc9b972c971041def5b6fe591ce to your computer and use it in GitHub Desktop.
Local holidays
open System
type DateOnly with
/// returns the date of Easter Monday for the given year
static member gaussEasterMonday (Y:int) =
let P = float Y / 100.0 |> floor // century
let M = // M depends on the century of year Y. For 19th century, M = 23. For the 21st century, M = 24 and so on
let Q = (13.0 + 8.0 * P) / 25.0 |> floor
int (15.0 - Q + P - (P / 4.0 |> floor)) % 30
let D = // The number of days to be added to March 21 to find the date of the Paschal Full Moon is
let A = float (Y % 19) // year in Metonic cycle
int (19.0 * A + float M) % 30
let E = // the number of days from the Paschal full moon to the next Sunday
let B = float (Y % 4) // leap days according to Julian calendar
let C = float (Y % 7) // non-leap year is 1 day longer than 52 weeks
let N = int (4.0 + P - (P / 4.0 |> floor)) % 7 // The difference between the number of leap days between the Julian and the Gregorian calendar
int (2.0 * B + 4.0 * C + 6.0 * float D + float N) % 7
match D, E with
| 29, 6 -> DateOnly(Y, 4, 20) // A corner case, when D is 29
| 28, 6 -> DateOnly(Y, 4, 19) // Another corner case, when D is 28
| _ , _ -> DateOnly(Y, 3, 1).AddDays(22 + D + E)
/// returns true if day is a normal workday (not weekend or a holiday)
member day.IsNormalWeekDay =
match day.DayOfWeek with
| DayOfWeek.Saturday | DayOfWeek.Sunday -> false
| _ ->
match day.Day, day.Month with
| 1, 1 // 1. januar
| 2, 1 // 2. januar
| 8, 2 // Prešernov dan
| 27, 4 // dan OF
| 1, 5 // 1. maj
| 2, 5 // 2. maj
| 25, 6 // dan državnosti
| 15, 8 // Marijino vnebovzetje
| 31, 10 // dan reformacije
| 1, 11 // dan spomina na mrtve
| 25, 12 // Božič
| 26, 12 // dan samostojnosti in enotnosti
-> false
| _ -> day <> DateOnly.gaussEasterMonday(day.Year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment