Thingaversary calculation error

ForumBug Collectors

Melde dich bei LibraryThing an, um Nachrichten zu schreiben.

Thingaversary calculation error

1Helenliz
Mrz. 29, 9:41 am

I knew my thingaversary was around now, but I wanted to check how many books I'm supposed to be buying.
LT seems a little confused on the subject:



I would have thought that it ought to be saying I have 1 day to my 11th thingaversary, not 365 to my 12th.

2knerd.knitter
Mrz. 29, 9:42 am

Ha! Probably a hardcoded check on 365 days is being confused by the leap year.

3lorax
Mrz. 29, 4:00 pm

Probably - it's a day off on my Thingaversary (in September) too.

4Helenliz
Mrz. 30, 10:40 am

Well something's changed for the better, it rightly thinks my thingaversary is today. >:-)

5MarthaJeanne
Mrz. 30, 10:48 am

I missed mine. Oh, well.

6knerd.knitter
Bearbeitet: Apr. 2, 12:40 pm

This is actually being caused by the fact that the numeric day of the year changes for all days after 2/29 in a leap year (e.g., March 1 is the 59th day of the year in non-leap years and the 60th day of the year in leap years); so we're checking if the numeric day of today is before your anniversary day. So if your anniversary was on March 1, then on February 29th, it's going to see both as the 59th day of the year and assume that means it needs to calculate to your next year's anniversary...

I'm not sure how we want to go about fixing this since it's such a corner case.

7MarthaJeanne
Apr. 2, 12:54 pm

Except that it will jeep recurring every 4 years if you don't fix it.

8AnnieMod
Bearbeitet: Apr. 2, 12:55 pm

>6 knerd.knitter: It is also the very first programming exercise when you are learning how conditionals work in a programming language... Not sure how exactly a leap year is "such a corner case" - throwing a "+1" in the calculation if you are after day 59 in a leap year should not be that hard, right? :)

PS: Does that mean that if someone joined on Feb 29, the site celebrates their anniversary on March 1? I am not sure if that is actually a bad idea - I am more curious than anything else.

9knerd.knitter
Apr. 2, 1:21 pm

I actually think that it would treat Feb 29 anniversaries as only happening in years that have Feb 29th. Because for checking if today is your anniversary it actually checks that the month/year match.

I'm aware that there are many ways to solve this, but the code is not straightforward and I don't want to break it. I think the issue only comes up on the day before your anniversary in a leap year (assuming you didn't also sign up in a leap year), which is why it was less noticeable.

10knerd.knitter
Apr. 2, 2:16 pm

I pushed a change for this which hopefully does not break the calculation for all thingaversaries.