Isn't converting years+months+days into a number exactly what (localtime)[7] does?
No, it only combines month and day, not year, month and day. Without taking the year into account, you need to work around leap years. I didn't have to. You have to, and you did, but incorrectly. (Years divisible by 4 are leap years, except those divisible by 100, except those divisible by 400.)
Actually, it just occured to me that both of our solutions have the following problems: They can't handle dates < Jan 1st 1970 or >= (some point in) 2038. Not very useful.
| [reply] [d/l] |
Again with the leap years...
As I explained to davidrw, the script as written (both mine and your version) uses current year +/- 1 year, not some arbitrary year in the past or future. At no time is any other year passed into a date function.
Which means it breaks if you can go back in time to run it before 1970 (which, if you've found a way to do it, please let me know cause there are some investments I'd like to make). It also breaks if you're still using it by 2038, but that's a Perl internal date problem and well beyond the control of this script (and every other Perl script written that uses current date).
So neither of our scripts will ever have to deal with dates < Jan 1st 1970 or >= (some point in) 2038. Not as written anyway
| [reply] |
Not again, still. You asked what was wrong with (localtime)[7], and I told you. You need to handle leap years (contrary to what you said). You attempted to do so, but it's buggy. It's wrong for 1900 and 2100, for starters. You might say that's not a problem because the system doesn't accept those dates, but it's a bug that it can't accept those dates. Once you fix your solution to accepts those dates, you'll have to fix the problem with the year 1900 and 2100. So that's two bugs. You're also off by a day (I think) when you run the program with certain combinations of current time, current date and current timezones for a total of three bugs.
| [reply] [d/l] |