[drupal-devel] date conversion
Gordon Heydon
gordon at heydon.com.au
Fri Jun 17 04:45:55 UTC 2005
Hi,
I have managed to work around this by converting a javascript date
parsing function that was inspired by strtotime().
http://simon.incutio.com/archive/2003/10/06/betterDateInput
Basically it uses regular expressions to create a very clean
implementation of a data parser. As the gmmkdate() was not broken on
linux (but is on windows so I used win_gmmkdate) I reimplemented this in
php, and work really good.
it most likely will not scale very well as it users preg_test() and
preg_grep() to do the matching but for just validating and converting
dates from forms it works extremely well.
Gordon.
On Mon, 2005-06-13 at 11:38 +0200, Gerhard Killesreiter wrote:
>
> On Mon, 13 Jun 2005, Gordon Heydon wrote:
>
> > Hi,
> > On Mon, 2005-06-13 at 06:59 +0200, Gerhard Killesreiter wrote:
> > >
> > > On Mon, 13 Jun 2005, Gordon Heydon wrote:
> > >
> > > > I was wondering if anyone knows of a decent method of converting dates
> > > > from text to a time.
> > > >
> > > > I did look at strtotime() but it will not convert anything before Jan 1,
> > > > 1970 which is a problem since it is going to be used for a date of birth
> > > > field, and some people will be over 35.
> > >
> > > Note: The valid range of a timestamp is typically from Fri, 13 Dec
> > > 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the
> > > dates that correspond to the minimum and maximum values for a
> > > 32-bit signed integer.)
> > >
> > > (from my version of the php manual entry for strtotime)
> > >
> > > print strtotime("60 years ago");
> > >
> > > gives me -774821398.
> >
> > Well that gives me on both my ubuntu and debian linux systems both give
> > me -1, It does say on the php site that it is windows and some linux
> > distributions.
>
> He, that's annoying. I tested on Debian too, and it fails. My earlier test
> was on a rather ancient SuSE distribution.
>
> > So if I use strtotime('31 Dec 1969') I get a -1, If it was giving me the
> > rangi that it would say it would me ok.
>
> http://de3.php.net/strtotime
>
> In the comments there is a safestrtotime() function that claims to support
> negative timestamps. Haven't tried it, though.
>
> Cheers,
> Gerhard
>
> !DSPAM:42ad557729171880090616!
>
More information about the drupal-devel
mailing list