FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mktime 2-digit vs 4-digit year
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
mktime 2-digit vs 4-digit year [message #175216] Fri, 26 August 2011 19:56 Go to next message
BKDotCom is currently offline  BKDotCom
Messages: 7
Registered: October 2010
Karma: 0
Junior Member
the mktime() year argument expects an integer
how does it know if I passed a 2-digit vs 4 digit value?
testing 0 <= year < 100 simply isn't good enough... what If I want to
specify years 0000 - 0099 (which should be possible on a 64-bit
system)
What keeps them from being being interpreted as 1970-2069? Or do
they?
(I don't have a 64-bit system to test on)

And if it does correctly accept the year 0000 - 0099, how could my own
code distinguish between 0000 and 00 ?
Re: mktime 2-digit vs 4-digit year [message #175218 is a reply to message #175216] Fri, 26 August 2011 23:14 Go to previous messageGo to next message
A is currently offline  A
Messages: 17
Registered: June 2011
Karma: 0
Junior Member
> the mktime() year argument expects an integer
> how does it know if I passed a 2-digit vs 4 digit value?
> testing 0 <= year < 100 simply isn't good enough... what If I want to
> specify years 0000 - 0099 (which should be possible on a 64-bit
> system)

mktime was not designed to do that. 0-99 are interpreted as 2 digits. mktime
accepts 2 or 4 digit year. valid range is from 1901 and 2038 on 32-bit
system so you can't even interpret anything outside of that range. it is
Year 2038 problem - http://en.wikipedia.org/wiki/Year_2038_problem

for anything outside of that range you probably need to make your own
library.

> And if it does correctly accept the year 0000 - 0099, how could my own
> code distinguish between 0000 and 00 ?

You can't. 0000 == 00. so 00 - 99 is simply an alias for 1900-1999.
Re: mktime 2-digit vs 4-digit year [message #175223 is a reply to message #175218] Sat, 27 August 2011 14:54 Go to previous messageGo to next message
BKDotCom is currently offline  BKDotCom
Messages: 7
Registered: October 2010
Karma: 0
Junior Member
On Aug 26, 6:14 pm, "A" <a...@a.a> wrote:
>> the mktime() year argument expects an integer
>> how does it know if I passed a 2-digit vs 4 digit value?
>> testing  0 <= year < 100 simply isn't good enough... what If I want to
>> specify years 0000 - 0099 (which should be possible on a 64-bit
>> system)
>
> mktime was not designed to do that. 0-99 are interpreted as 2 digits. mktime
> accepts 2 or 4 digit year. valid range is from 1901 and 2038 on 32-bit
> system so you can't even interpret anything outside of that range. it is
> Year 2038 problem -http://en.wikipedia.org/wiki/Year_2038_problem
>
> for anything outside of that range you probably need to make your own
> library.

That's just it, I don't know how it would be possible to code in
straight PHP
unless it accepted a string for the year" "0000" - "0099" and use
strlen()

I've created a datetime_mktime() func that uses the DateTime class and
DateTime::add / DateTime::sub to create the date thus avoiding the 32-
bit limitation on 32-bit systems.
It takes the same args as mktime() it'd be nice if it were able to
accept 00-99 and know that's referring to 1970-2069 and also accept
0000-0099
Re: mktime 2-digit vs 4-digit year [message #175225 is a reply to message #175223] Sat, 27 August 2011 18:05 Go to previous messageGo to next message
BKDotCom is currently offline  BKDotCom
Messages: 7
Registered: October 2010
Karma: 0
Junior Member
Executive decision on my part.
If you pass 85 to my function it will be interpreted literally as year
85 (not 1985)
however, It'll also accept strings for the year. "85" will be
interpreted as 1985. In case someone needs that 2-digit
functionality.

What bonehead is using 2-digit years?! :)
Re: mktime 2-digit vs 4-digit year [message #175229 is a reply to message #175225] Sun, 28 August 2011 15:15 Go to previous message
A is currently offline  A
Messages: 17
Registered: June 2011
Karma: 0
Junior Member
mktime is more like a port of 32bit c++ version of mktime which functions
has the same valid range.
but in c++ there is also mktime64 for ages which i haven't seen in php.

so there is nothing bonehead... it's just how it is made to work. accept it
or find some alternative how to do it.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Top 10 Wrong Ideas About PHP
Next Topic: fopen error
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 14:26:10 GMT 2024

Total time taken to generate the page: 0.02283 seconds