4 ms·
Not sure how the doomsday works, but there's a quick way to calculate the day of week just memorizing single digit codes for months. Might be easier to grok fro
by hashmymustache 12y ago
Not sure how the doomsday works, but there's a quick way to calculate the day of week just memorizing single digit codes for months. Might be easier to grok from a small script. This is for current century (2000s) in coffeescript:
calculateDay = (year,month,day) ->
y = (year-2000)%28
m = [6,2,2,5,0,3,5,1,4,6,2,4][month]
if month < 2 and y%4==0
m-= 1
y += y/4|0
days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
return days[(y+m+day)%7]
---
For years 1600s through current century here's a jsfiddle with a slightly longer method with verification: http://jsfiddle.net/9zp0zkxz/ http://jsfiddle.net/9zp0zkxz/
Edit: no idea how to work spacing on comments here
- ColinWright 12y ago> no idea how to work spacing on comments here * Blank lines create new paragraphs, Blank line followed by lines with leading spaces create pre-formatted text - intended for inserting code. Under most circumstances, asterisks around text creates italics, the exception is when the asterisk is surrounded by space. -- https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc
- hashmymustache 12y agoah, thank you
- elwell 12y agocalculateDay = (year, month, day) -> y = (year - 2000) % 28 m = [6,2,2,5,0,3,5,1,4,6,2,4][month] m-- if month < 2 and y % 4 is 0 y += (y / 4) | 0 ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][(y + m + day) % 7]