Last active
June 9, 2017 07:39
-
-
Save kosinix/dcdc753847dff11a324381253e59a65e to your computer and use it in GitHub Desktop.
Formula for displaying days in a Gregorian calendar month
This file contains hidden or 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
prefixLength - The number of pads before the first calendar day | |
suffixLength - The number of pads after the last calendar day | |
monthFirstWeekDay - The weekday of first month day. int 0-6 where 0 is Sunday and 6 is Saturday | |
monthLastWeekDay - he weekday of last month day. int 0-6 where 0 is Sunday and 6 is Saturday | |
calendarWeekStart - The weekday to which the calendar days start. int 0-6 where 0 is Sunday and 6 is Saturday | |
Pseudocode: | |
prefixLength = monthFirstWeekDay - calendarWeekStart | |
if(prefixLength < 0){ | |
prefixLength += 7; | |
} | |
suffixLength = 6 - (monthLastWeekDay - calendarWeekStart) | |
if(suffixLength > 6){ | |
suffixLength = suffixLength - 7; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment