Skip to content

Instantly share code, notes, and snippets.

@kosinix
Last active June 9, 2017 07:39
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 kosinix/dcdc753847dff11a324381253e59a65e to your computer and use it in GitHub Desktop.
Save kosinix/dcdc753847dff11a324381253e59a65e to your computer and use it in GitHub Desktop.
Formula for displaying days in a Gregorian calendar month
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