CE-Programming / toolchain

Toolchain and libraries for C/C++ programming on the TI-84+ CE calculator series
https://ce-programming.github.io/toolchain/index.html
GNU Lesser General Public License v3.0
528 stars 53 forks source link

localtime reports the wrong day on leap years #469

Closed TheMiningTeamYT closed 10 months ago

TheMiningTeamYT commented 10 months ago

On leap years, if you use localtime, tm_mday from the returned struct will be 1 too high until March 1st. Here's my code: time.tar.gz

mateoconlechuga commented 10 months ago

Can you please be more descriptive?

TheMiningTeamYT commented 10 months ago

Somehow I expected that when I submitted the issue. If you call localtime (from time.h/ctime), it returns a pointer to a tm struct That struct has a property (tm_mday) that is supposed to reflect the current day of the month. However, if it is before March 1st on a leap year, the value it returns is 1 higher than it should be. (For instance, on January 1st, 2024 it returns 2 [as in January 2nd, 2024] instead of 1) (It works fine if the date is March 1st or after or if the year is not a leap year) You can see this with the code I attached. (If you press '4' to open the clock, it shows the current reported day of the month, which is taken directly from the struct pointer returned bylocaltime)

mateoconlechuga commented 10 months ago

This is now fixed in the latest nightly! Thanks for the report

mateoconlechuga commented 10 months ago

Also @TheMiningTeamYT have you used the asctime or strftime C functions before? I imagine it would greatly clean up your code.

TheMiningTeamYT commented 10 months ago

As a matter of fact, no! I'll try it sometime.