phpLens
 home  products examples manual  faq support forum  contact news  login store

Forums: phplens   adodb
Forums:   ADOdb Help & Dev:   Replies 
New ReplySearch
Topic: adodb_date problem
author: Jason Pell   created: 08-08-2003 01:43:31 AM
Hi,

The following code:
echo(adodb_date("F j, Y, g:i a", adodb_mktime(0, 0, 0, 1, 1, 2054)));

Returns:
December 32, 2053, 12:00 am

I tracked it down to the _adodb_getdate function. The code print_r(_adodb_getdate(adodb_mktime(0, 0, 0, 1, 1, 2054), true));

Displays:

Array
(
[seconds] => 0
[minutes] => 0
[hours] => 0
[mday] => 32
[mon] => 12
[year] => 2053
[yday] => 365
[leap] =>
[ndays] => 31
)

Notice the '32' value in mday and the previous year.

Now the interesting thing is, if I set the 'seconds' argument to 1 instead of zero, I get a different value,
closer to what I want.

The code:
echo(adodb_date("F j, Y, g:i a", adodb_mktime(0, 0, 1, 1, 1, 2054)));

Displays:
January 1, 2054, 12:00 am

The code:
print_r(_adodb_getdate(adodb_mktime(0, 0, 1, 1, 1, 2054), true));

displays:

Array
(
[seconds] => 1
[minutes] => 0
[hours] => 0
[mday] => 1
[mon] => 1
[year] => 2054
[yday] => 0
[leap] =>
[ndays] => 31
)

So it appears that the _adodb_getdate(...) function cannot handle the hour/minute/seconds parameters all being zero. If I set the hour to one, and leave minutes and seconds zero, I get a similiar correct result.

I believe this is a bug, as mktime is supposed to support zero for these values.

I am using Redhat 9.0 and PHP 4.2.2

I downloaded the
- 1 July 2003 0.09

version of the adodb-time.inc.php script

Thanks
Jason
Topic: Re:adodb_date problem
author: Jason Pell   created: 08-08-2003 02:10:32 AM
Hi,

If I change line 582, from:
if ($d <= 0) {

To:

if ($d < 0) {

The problem disappears. I am currently running the test suite to see what effect this has.

Except for some DST issues with my Australian PHP, the change does not seem to have caused any issues.

Please note that this problem with zero seconds/minutes/hours is only a problem for all years after 1970 (all positive integers in other words)

The test plan probably needs to be expanded a bit more to test for these values.

Cheers
Jason
Topic: Re:adodb_date problem
author: John Lim   created: 08-08-2003 07:39:16 AM
Thx - Fixed.
Topic: Re:adodb_date problem
author: w_w   created: 31-01-2008 06:10:25 AM
echo '01-12-2007+12month => '.adodb_date("d-m-Y",adodb_mktime(0,0,0,(12+12),1,2007));
prints:
01-12-2007+12month => 01-01-2009
when:
echo '01-12-2007+12month => '.date("d-m-Y",mktime(0,0,0,(12+12),1,2007));
prints
01-12-2007+12month => 01-12-2008

and

echo '01-12-2007+24month => '.adodb_date("d-m-Y",adodb_mktime(0,0,0,(12+24),1,2007));
prints:
01-12-2007+12month => 01-01-2010
when:
echo '01-12-2007+24month => '.date("d-m-Y",mktime(0,0,0,(12+24),1,2007));
prints:
01-12-2007+24month => 01-12-2009

Where is 1 month?

code is:
<?php
require_once("adodb-time.inc.php");

$cd='2007-12-01';
$year=substr($cd,0,4);
$month=substr($cd,5,2);
$day=substr($cd,8,2);

for ($m=1;$m<=36;$m++)
{
define('ADODB_TEST_DATES',0);
$d1=adodb_date("d-m-Y",adodb_mktime(0,0,0,($month+$m),$day,$year));
$d2=date("d-m-Y",mktime(0,0,0,($month+$m),$day,$year));
if ($m>9) $mm=$m; else $mm='0'.$m;
if ($d1<>$d2) {$b='<b style="color:#FF0000">'; $ok="#";} else {$b='<b style="color:#000000">'; $ok="=";}
echo "<br>define('ADODB_TEST_DATES',0) - start=".$cd.' + month='.$mm.' => adodb_date='.$b.$d1.'</b> date='.$b.$d2.'</b> '.$ok;

define('ADODB_TEST_DATES',1);
$d1=adodb_date("d-m-Y",adodb_mktime(0,0,0,($month+$m),$day,$year));
$d2=date("d-m-Y",mktime(0,0,0,($month+$m),$day,$year));
if ($d1<>$d2) {$b='<b style="color:#FF0000">'; $ok="#";} else {$b='<b style="color:#000000">'; $ok="=";}
echo "<br>define('ADODB_TEST_DATES',1) - start=".$cd.' + month='.$mm.' => adodb_date='.$b.$d1.'</b> date='.$b.$d2.'</b> '.$ok;

echo '<br>--------------------------------------------------------------------------------------------------------------------------------------------------';
}
echo '<br>--------------------------------------------------------------------------------------------------------------------------------------------------';
define('ADODB_TEST_DATES',0);
$d1=adodb_date("d-m-Y",adodb_mktime(0,0,0,($month+600),$day,$year));
$d2=date("d-m-Y",mktime(0,0,0,($month+600),$day,$year));
$mm=600;
if ($d1<>$d2) {$b='<b style="color:#FF0000">'; $ok="#";} else {$b='<b style="color:#000000">'; $ok="=";}
echo "<br>define('ADODB_TEST_DATES',0) - start=".$cd.' + month='.$mm.' => adodb_date='.$b.$d1.'</b> date='.$b.$d2.'</b> '.$ok;

define('ADODB_TEST_DATES',1);
$d1=adodb_date("d-m-Y",adodb_mktime(0,0,0,($month+600),$day,$year));
$d2=date("d-m-Y",mktime(0,0,0,($month+600),$day,$year));
if ($d1<>$d2) {$b='<b style="color:#FF0000">'; $ok="#";} else {$b='<b style="color:#000000">'; $ok="=";}
echo "<br>define('ADODB_TEST_DATES',1) - start=".$cd.' + month='.$mm.' => adodb_date='.$b.$d1.'</b> date='.$b.$d2.'</b> '.$ok;
echo '<br>01-12-2007+12month => '.adodb_date("d-m-Y",adodb_mktime(0,0,0,(12+12),1,2007));
echo '<br>01-12-2007+24month => '.adodb_date("d-m-Y",adodb_mktime(0,0,0,(12+24),1,2007));
echo '<br>01-12-2007+12month => '.date("d-m-Y",mktime(0,0,0,(12+12),1,2007));
echo '<br>01-12-2007+24month => '.date("d-m-Y",mktime(0,0,0,(12+24),1,2007));
?>
Topic: Re:adodb_date problem
author: w_w   created: 31-01-2008 07:43:56 AM
$d1=adodb_gmdate("d-m-Y",adodb_gmmktime((13),0,0,($month+$m),$day,$year));
$d2=date("d-m-Y",mktime(13,0,0,($month+$m),$day,$year));

gives errors only for 12, 24, 6 month:
define('ADODB_TEST_DATES',0) - start=2007-12-01 + month=12 => adodb_date=01-01-2009 date=01-12-2008 #
define('ADODB_TEST_DATES',1) - start=2007-12-01 + month=12 => adodb_date=01-01-2009 date=01-12-2008 #

define('ADODB_TEST_DATES',0) - start=2007-12-01 + month=24 => adodb_date=01-01-2010 date=01-12-2009 #
define('ADODB_TEST_DATES',1) - start=2007-12-01 + month=24 => adodb_date=01-01-2010 date=01-12-2009 #
Topic: Re:adodb_date problem
author: w_w   created: 31-01-2008 07:50:54 AM
more results:
define('ADODB_TEST_DATES',0) - start=2007-11-01 + month=13 => adodb_date=01-01-2009 date=01-12-2008 #
define('ADODB_TEST_DATES',1) - start=2007-11-01 + month=13 => adodb_date=01-01-2009 date=01-12-2008 #

define('ADODB_TEST_DATES',0) - start=2007-01-01 + month=23 => adodb_date=01-01-2009 date=01-12-2008 #
define('ADODB_TEST_DATES',1) - start=2007-01-01 + month=23 => adodb_date=01-01-2009 date=01-12-2008 #

define('ADODB_TEST_DATES',0) - start=2007-02-01 + month=22 => adodb_date=01-01-2009 date=01-12-2008 #
define('ADODB_TEST_DATES',1) - start=2007-02-01 + month=22 => adodb_date=01-01-2009 date=01-12-2008 #

etc.
Topic: Re:adodb_date problem
author: w_w   created: 31-01-2008 08:02:21 AM
error in code:
if ($mon > 12) {
$y = floor($mon / 12);
$year += $y;
$mon -= $y*12;
} else if ($mon < 1) {
$y = ceil((1-$mon) / 12);
$year -= $y;
$mon += $y*12;
}


if ($mon > 12) {
$y = floor(($mon-1) / 12);
$year += $y;
$mon -= $y*12;
} else if ($mon < 1) {
$y = ceil((1-$mon) / 12);
$year -= $y;
$mon += $y*12;
}
Topic: Re:adodb_date problem
author: John Lim   created: 31-01-2008 09:37:53 PM
Thanks, this will be added in the next release.
Page 1
New ReplySearch

View Source

email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800