Re: getting a string result from Date
| From: | Lorenzo Alberton | Date: | Fri, 02 Apr 2004 15:42:49 +0000 |
| Subject: | Re: getting a string result from Date | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11585@lists.php.net to get a copy of this message | ||
Hi Demian,
On Fri, 02 Apr 2004 09:44:49 +0100, Demian Turner wrote:
> Hi Lorenzo
> please give the code a try, i was baffled to find the second
> $currdate assignment doesn't work when it's fed back into the
> argument of the Date object in the next iteration of the loop.
sorry, I had only looked at the first run,
didn't notice $currDate was fed back in the loop.
Anyway, PEAR::Date constructor accepts one of the following standards:
DATE_FORMAT_ISO, ISO_BASIC, ISO_EXTENDED, TIMESTAMP, UNIXTIME.
your first assignment ($currDate = "2003-9-04";) is invalid,
so by default $date->year is set to 0, $date->day=1, $date->month=1.
When you call subtractSpan(), though, Date_Calc::dateToDays()
is internally called, and that method supposes the passed date is
in the ISO format, without any check. In this method, the 0-1-1
date is somewhat changed into the date of the current day.
Since in the loop you keep on passing an invalid date to Date()
constructor, the same sequence described above happens
at each iteration.
Wrapping up... I don't think it's a bug in Date(), (even if I agree
a better check in dateToDays() wouldn't hurt),
because the input is not valid (at least according to Date
capabilities), so you can't expect a valid output ;-)
HTH
Lorenzo