toma has asked for the wisdom of the Perl Monks concerning the following question:
Is there a standard way to mark this type of code, or is there a simple way to design code to make this easy to fix?
It should work perfectly the first time! - toma
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 2038 bug
by tachyon (Chancellor) on Apr 11, 2003 at 05:19 UTC | |
Put all your time manipulation code in a module called Y2038::Problem ??? Seriously if you abstract your time code to a single location it will be easy to modify. But realistically Y2038 is only an issue if time_t is still a 4 byte int in 2038. It is quite reasonable to expect that 64 bit machines will be the norm and quite possibly 8 byte ints. In Perl there is unlikely to be a major issue as our use of time is abstracted from the raw 4 byte dependent time_t. As a result in Perl 6.01 in 2038 (Oh what a cynic) the basic time() function could quite easily be modified to return an 8 byte int into a Perl scalar and thus there is not real issue provided that the Perl was comiled with 8 byte int support, etc. The ugly Y2K hack is to assume that times say < 2147483647 / 2 (make it a small a the number of extra years you want to wring out of your code) represents a rollover so proceed accordingly. This potentially gives you another 34 years worth of mileage out of it - assuming that there are not valid dates before 2004 you are processing in 2038 of course. You could facilitate such ugly hacks by putting all time functions in a module. ie
For those who might wonder why 2038.....
cheers tachyon s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print | [reply] [d/l] [select] |
by Abigail-II (Bishop) on Apr 11, 2003 at 07:26 UTC | |
2038 is not going to be disaster, unless too many will think that just upgrading to a 64 bit time_t will magically solve all problems. (If it were that simple, we could have let localtime() return a 4 digit year to avoid Y2K.) Some time ago, I saw the timetable SUN is going to use to introduce a 64 bit time_t value. It's going to be a 10+ year traject. Abigail | [reply] |
by logan (Curate) on Apr 11, 2003 at 17:36 UTC | |
The rationale given for why it hadn't been upgraded with all the other systems was that there was a short term advantage in cost savings, and by the time the problem surfaced, the executives who made the decisions would be long gone. Sure, it's a Dilbertism, but in the wake of the corporate scandals of 2001, doesn't it ring true? Assuming that we'll all be on 64-bit (or 128-bit, or embryonic monkey-brain) processors at some point in the nebulous future is a mistake. Someone out there will decide not to upgrade. Some of my company's customers still use Windows 95. Last year I was at an airport, and the application displaying the arrivals and departures had crashed The terminal was showing a Windows 98 desktop. Even if you decide that someone can fix it "later", possibly in the mad dash to fix legacy unix code in Fall of 2037, please document the issue.
-Logan | [reply] |
by tachyon (Chancellor) on Apr 11, 2003 at 11:08 UTC | |
What I don't really understand is why you could not make time_t an unsigned 4 byte int and thus get another 68 odd years out of it. Leaving aside the problems with C code that expects it to be signed. Why was it unsigned in the first place anyway? As you say there are a lot of issues to be resolved. My main point was to abstract the time handling so at least that can of worms is all in the same place which will make it easier to deal with - all other things being equal. cheers tachyon s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print | [reply] |
by halley (Prior) on Apr 11, 2003 at 14:04 UTC | |
by Abigail-II (Bishop) on Apr 11, 2003 at 14:50 UTC | |
by grantm (Parson) on Apr 11, 2003 at 08:48 UTC | |
But realistically Y2038 is only an issue if time_t is still a 4 byte int in 2038. I'm not trying to be a panic monger (lord knows the Y2K 'bug' brought enough of them out of the woodwork!) but the problem is real now. There are plenty of reasons you might want to do a date calculation that went beyond 2038, for example printing a table of predicted values by year for a retirement investment policy, or calculating a mortgage amortisation table, or working out what day of the week to schedule your retirement party :-). Don't get me wrong, I'm not suggesting these things are impossible or even hard to do. I'm merely saying that the standard tools like time(), localtime() and Time::Local() will let you down. Dave Rolsky's recent article on Perl.com provides some answers. | [reply] |
by Abigail-II (Bishop) on Apr 11, 2003 at 09:00 UTC | |
There are plenty of reasons you might want to do a date calculation that went beyond 2038, for example printing a table of predicted values by year for a retirement investment policy, or calculating a mortgage amortisation table, or working out what day of the week to schedule your retirement party.Sure, but those are dates. One doesn't calculate a mortgage amortisation table with a precision of a second, nor are parties planned to start at a specific second. Abigail | [reply] |
by grantm (Parson) on Apr 11, 2003 at 10:36 UTC | |
by tbone1 (Monsignor) on Apr 14, 2003 at 12:33 UTC | |
by pg (Canon) on Apr 11, 2003 at 06:11 UTC | |
The $begin - $end approach would not work, assume that we get both from a function like time(). The problem is that, for time(), after it steps over the biggest positive integer, it would go directly to the smallest negative integer, i.e. the negative integer with the biggest absolute value. For example, if $begin is 2038-01-18-20:14:06, and $end is 2038-01-18-20:14:07, although there is only 1 second difference, by calling time(), and do $begin - $end, you will get: 2 ** 31 - 1 - (- 2 ** 31) = 2 ** 32 - 1 | [reply] |
by tachyon (Chancellor) on Apr 11, 2003 at 06:18 UTC | |
Of course it will work. I said abstract *all time manipulation* into a module. This obviously includes getting the current time from time(). The abstraction is the main thing as it lumps all the problems in one festering little bucket. cheers tachyon s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print | [reply] |
Re: 2038 bug
by hossman (Prior) on Apr 11, 2003 at 06:43 UTC | |
I don't see a lot of middle ground on an issue like this. If you're going to worry about it, worry about it all the way and make sure it works ... otherwise just put a conservative comment in the User Manual that says something like "Use this software with dates greater them 2010 at your own risk" and don't make a lot of work for yourself that may or may not acctually ever be usefull to someone who may or may not be looking at your code. Update: DateTime works great... 2203-04-11T06:52:55 | [reply] [d/l] |
Re: 2038 bug
by IndyZ (Friar) on Apr 11, 2003 at 05:50 UTC | |
The only group Perl project that I've ever worked on decided to use FIXME with an explanation for known broken code. It made it simple to do an update from CVS, then run a "grep FIXME" on the source. --IndyZ | [reply] [d/l] |
Re: 2038 bug (consider TAI64)
by grinder (Bishop) on Apr 11, 2003 at 10:09 UTC | |
You might be interested at looking at Daniel J. Bernstein's implementation of TAI (temps atomique international), a 64-bit representation of time values. It can deal with second, nanosecond or attosecond precision, depending on your requirements. cr.yp.to/libtai/tai64.html He has a number of essays about time that are worth reading. It should be noted that djb is considered a controversial character in some circles. _____________________________________________ | [reply] |
Re: 2038 bug
by pg (Canon) on Apr 11, 2003 at 06:49 UTC | |
| [reply] [d/l] |
Y2K once again!
by htoug (Deacon) on Apr 11, 2003 at 08:10 UTC | |
The best solution is to go with a module that allows much greater range of dates than the 1970 to 2038 range that time_t allows with 32 bits. We changed to Date::Calc (and used the C-library for all C and C++ programs) so we wont have problems before sometime around year 2380(-70 or so years) when our RDBMS's date type goes out of range! | [reply] |
Re: 2038 bug
by zenn (Sexton) on Apr 11, 2003 at 13:45 UTC | |
This means that depending on your platform the bug can happen earlier enough to begin to think about it now. Nevertheless this depends on the size of your time_t type that is usually based in the long c type(in linux I mean). So since kernel 2.3 the developers are thinking about extending this to 64 bits to avoid this kind of problem. I don't know about other platforms, but I think it is easy enough to handle this problem, and this will be addressed soon. Zenn | [reply] [d/l] |
Re: 2038 bug
by hatter (Pilgrim) on Apr 11, 2003 at 11:00 UTC | |
the hatter | [reply] [d/l] |
Re: 2038 bug
by mattr (Curate) on Apr 13, 2003 at 15:17 UTC | |
$ perl -e 'print scalar localtime time*3;' Thu Sep 28 21:26:38 1933 Ouch!
There are some interesting pages at: The last link has specific advice for your case: "What can be done?"But the above rollover will only happen if you are using the same perl on the same machine/OS/BIOS, I think. The source code of your program would not have to change if it is interpreted by a (yet to be created?) more modern version of perl. That said, it would be nice if we had a way to explain perl modules to programs with an aim to automated software integration. Some keywords- "web annotation","syntactic web", "natural language processing" will probably be full grown by then (see some in google directory). But that seems to be in early stages, we could use something perlish or corbaish even now. So I think your question is very relevant to us now too. Even with today's technology we should be able to describe characteristics of our programs in a way that a machine can understand. Also, there is currently no standardized way of describing Y2.038K problems. Ultimately things like failure modes of 2038-challenged unix software and embedded systems can be described with some kind of interface description language - maybe perl is good for this (Consider perl Makefile.PL as a forerunner). That way we can hope that when nearly every piece of hardware in existence today crashes and burns, the important things can be virtualized on 64+ bit machines that scan these descriptions of dead systems and rescue us. Doesn't seem like science fiction to me.. Anyway I would like to see something more parseable in manpages and whatnot, perldocs could gain another section for machine-readable descriptions too. Anyway to directly answer your question (how to annotate your program) maybe it would be useful to put tags in comments to indicate dangerous lines, and provide a separate file which describes the problems. You could also try describing exactly what is dangerous about it in simplified english inside <Y2.038K> </Y2.038K> tags, it might just work! | [reply] |
Re: 2038 bug
by Anonymous Monk on Apr 11, 2003 at 05:03 UTC | |
Why not just fix it? Post the code, we'll help out, honest. | [reply] |
by pg (Canon) on Apr 11, 2003 at 05:10 UTC | |
then run this perl program: you will get a negative number back. That's the limitation sort of thing, not a bug in his code. Try this code: Look at how close those two numbers are, now you realize that's the up limitation of positive integers on 32 bit machine. I don't worry about this too much, most likely when 2038 approaches, 64 bit or something even better will dominate. (Set time to 2038-01-18-20:14:06, and see what happens to the above demo, also 2038-01-18-20:14:07) | [reply] [d/l] [select] |
by Anonymous Monk on Apr 11, 2003 at 05:24 UTC | |
Thanks for the correction, the thought had crossed my mind, but I didn't think we were anywhere near that close (guess I should do my math next time ;). time to dust off the ol' quantum computer, only 35 years to get it working! :) | [reply] |
by Courage (Parson) on Apr 11, 2003 at 05:29 UTC | |
Re: 2038 bug
by bart (Canon) on Apr 11, 2003 at 22:09 UTC | |
And I really don't see a reason why the epoch couldn't just stay the same, Jan 1 1970 00:00:00 GMT. In other words: I don't really expect code like yours to break, provided your Perl port will be upgraded by then — and, as Abigail wrote, your system can handle it. Honestly, I do expect that that will turn out to be the biggest problem: timestamps on file systems. | [reply] |
Re: 2038 bug
by dragonchild (Archbishop) on Apr 14, 2003 at 18:10 UTC | |
------ Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. | [reply] |