Last active
March 11, 2020 17:00
-
-
Save WebFreak001/ca9e84d6e18b76666d88879972ecd6c7 to your computer and use it in GitHub Desktop.
calculate from ISO week calendar date (year, week, weekday) into gregorian calendar date (year, month, date)
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
/* hoping to get this into phobos: https://github.com/dlang/phobos/pull/7420 */ | |
Date dateFromISOWeek(short isoWeekYear, ubyte isoWeek, DayOfWeek weekday) @safe pure | |
{ | |
immutable adjustedWeekday = weekday == DayOfWeek.sun ? 7 : weekday; | |
immutable dayOffset = (isoWeek - 1) * 7 + adjustedWeekday; | |
Date date = Date(isoWeekYear, Month.jan, 3); | |
immutable startOfYear = date.dayOfWeek; | |
return date + days(dayOffset - startOfYear); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment