News for hackers. Stuff that matters.
Re:When Can I Reuse This Calendar? by unixhero on Tuesday July 09, 2019 @12:12AM (#20388964)
Would be great to see the source code of this. I think the logic used would be fun to read.
Re:When Can I Reuse This Calendar? by wartijn_ on Tuesday July 09, 2019 @01:41AM (#20389260)
I don't have the source code of this site, but checking if a calendar can be used again is pretty easy.

1. Check which weekday the year starts

2. Check if this year is a leap year.

If the year starts on the same weekday as another year and the leap-yeariness is the same, the year is the same.

With this info it's really easy to use your favorite date library to check which years match, but you can also do that manually.

Each year starts on the next weekday that the previous year did. (2019-01-01 was a Tuesday, 2020-01-01 will be a Wednesday) except when that previous year was a leap year. In that case one day is skipped.

Edit:ninja'd by jcranmer

Re:When Can I Reuse This Calendar? by nicky0 on Tuesday July 09, 2019 @04:45AM (#20389970)
Cool so there are 14 classes of year.
Re:When Can I Reuse This Calendar? by mxtopher on Tuesday July 09, 2019 @12:23AM (#20389013)
I wouldn't be surprised if it was just a for loop checking for all the years in a range, whether they start on the same day of week, and are/are not leap years :)
Re:When Can I Reuse This Calendar? by jcranmer on Tuesday July 09, 2019 @01:34AM (#20389243)
The calculations are actually really easy. Note that the length of a (regular) year is 1 mod 7, which means weekdays slip by 1 day each year, except for leap years. Over the 400-year Gregorian calendar cycle, there are 97 leap years, for a total of 497 days of slip... so adding 400 years to the current calendar year will always yield the same calendar.

More specifically, there are 14 possible calendars. The leap year cycle is 4 days (excluding the 100 year skips), and the weekday cycle is 7 days, so the leap year×weekday cycle is 28 years. So the starting weekdays are on a 28-year cycle, but you have to slip your resulting calculation by the number of centuries from the beginning of the 400-year cycle (i.e., integer division of year by 100). You'll reuse a leap year calendar in 28 years (40 years, if it crosses a round-hundred year), and you'll reuse a non-leap year calendar in 6 or 11 years (12 or 6 years, if it cross a round-hundred year).

The easiest way to code it is to just precompute the year % 400 table and report the results.

Re:When Can I Reuse This Calendar? by lifthrasiir on Tuesday July 09, 2019 @03:08AM (#20389602)
> The easiest way to code it is to just precompute the year % 400 table and report the results.

If you are interested, Chrono [1] internally uses the exact table. Constants there refer to dominical letters [2].

[1] https://github.com/chronotope/chrono/blob/a4488007272569f752...

[2] https://en.wikipedia.org/wiki/Dominical_letter

Re:When Can I Reuse This Calendar? by ComputerGuru on Tuesday July 09, 2019 @08:09AM (#20390958)
> The leap year cycle is 4 days (excluding the 100 year skips)

I think you mean “The leap year cycle is 4 days (excluding the 100 year skips, except every fourth 100 years when they don’t),” eg how 2000 was a leap year despite this individual rule.

(I know it’s accounted for elsewhere in the modulo logic, but you shouldn’t resist the impulse to point out just how crazy it all is!)

Re:When Can I Reuse This Calendar? by jcranmer on Tuesday July 09, 2019 @08:57AM (#20391235)
The 400 year rule is already accounted for by taking the year mod 400. 2000, 2400, 2800, etc. will all use the same calendar.
Re:When Can I Reuse This Calendar? by ComputerGuru on Tuesday July 09, 2019 @09:19AM (#20391385)
Yes, I did mention you had it taken care of, just not explicitly pointed out :)
Re:When Can I Reuse This Calendar? by ivolimmen on Tuesday July 09, 2019 @12:26AM (#20389024)
Or the calculations where done once and now it's stored in a database.
Re:When Can I Reuse This Calendar? by avaika on Tuesday July 09, 2019 @03:45AM (#20389732)
Once and manually. On an oily napkin in canteen.
Re:When Can I Reuse This Calendar? by Amorymeltzer on Tuesday July 09, 2019 @06:44AM (#20390497)
I wonder where and how he got all the old calendar images. Seems like that'd be a fairly tedious process, not to mention aligning matching each to the appropriate year(s).
Re:When Can I Reuse This Calendar? by theon144 on Tuesday July 09, 2019 @10:58AM (#20392409)
It doesn't seem to match up to any info offered by the site, I think it's just a random selection...