PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #3330

Time elements from mysql are not working due to date parsing problem

Details

Submitted2005-01-30 16:37 UTC
Fromabarrei at gmail dot com
Assignedjustinpatrin
StatusNo Feedback
PackageDB_DataObject_FormBuilder
PHP Version4.3.8
OSUnix
Roadmaps(Not assigned)

Comments

[2005-01-30 16:37 UTC] abarrei at gmail dot com

Description:
------------
Mysql select for time fields returns the time in the folowing format: HH:mm:ss

Example 11:00:00.

I looked through through the Formbuilder.php and I found you use the Date Package for the _date2array callback function and its conversion. This package receives and ISO 8601, and as an only time string is not compliant with that standard, the Date objects returns empty.

* @version $Id: FormBuilder.php,v 1.119 2005/01/28 01:23:45 justinpatrin Exp $

I add the following line to the _date2array function below line 1864

// Convert to ISO 8601 format
// Specialy time objects
$date = strftime("%Y-%m-%dT%T",strtotime($date));

I think its a nice fix, becouse it wouldn't mess with the other types, but I haven't thought too much about any side effects though.

I also noticed that the _array2date function you provide is not behaving normally. THus, you have these if clauses:

if (isset($year) && isset($month) && isset($dateInput['d'])) {

and

if (isset($hour) && isset($dateInput['i']) && isset($dateInput['s'])) {

so you expect the all year, months and dates exist for building the date string, and that all hours, minutes, and seconds exists for building the time string.

As dateFormatElement and timeFormatElement let you lack of any of those fields, for example:

$timeFormatElement = "H:i"

It would be nice to have that function expect that and build the date with a default value (seconds=0) for example, becouse if not, the string is empty and a value of 0 is inserted into the database.

I fix that function to, only the part of the time, that is what I am needing right now, I did the following fix in the if clause of the time part:

if (isset($hour) && isset($dateInput['i'])) {
if (!empty($strDate)) {
$strDate .= ' ';
}
$strDate .= $hour.':'.$dateInput['i'];
if (isset($dateInput['s']))
{
$strDate .= ':'.$dateInput['s'];
}
if (isset($ampm)) {
$strDate .= ' '.$ampm;
}
}

of course I am still expecting and $hour and minuts from the time object.

I know this can be overriden but I would be nice to have it fixed on the package.

Let me know what you think and If I have the time when I finished what I need to finish right now I can give you a more complete array2date following this needs, if you think they are worth it.

Reproduce code:
---------------
N/A

Expected result:
----------------
N/A

Actual result:
--------------
N/A

[2005-01-30 16:51 UTC] abarrei at gmail dot com

A different _array2date function with the defaults values I was talking about. What do you think?

function _array2date($dateInput, $timestamp = false)
{
if (isset($dateInput['M'])) {
$month = $dateInput['M'];
} elseif (isset($dateInput['m'])) {
$month = $dateInput['m'];
} elseif (isset($dateInput['F'])) {
$month = $dateInput['F'];
}
if (isset($dateInput['Y'])) {
$year = $dateInput['Y'];
} elseif (isset($dateInput['y'])) {
$year = $dateInput['y'];
}

if (isset($dateInput['H'])) {
$hour = $dateInput['H'];
} elseif (isset($dateInput['h'])) {
$hour = $dateInput['h'];
}
if (isset($dateInput['a'])) {
$ampm = $dateInput['a'];
} elseif (isset($dateInput['A'])) {
$ampm = isset($dateInput['A']);
}

$strDate = sprintf(
"%04d-%02d-%02d %02d:%02d:%02d%s",
isset($year) ? $year : 0 ,
isset($month) ? $month : 0 ,
isset($dateInput['d']) ? $dateInput['d'] : 0 ,
isset($hour) ? $hour : 0 ,
isset($dateInput['i']) ? $dateInput['i'] : 0 ,
isset($dateInput['s']) ? $dateInput['s'] : 0 ,
isset($ampm) ? " ".$ampm : ""
);

//$this->debug('<i>_array2date():</i> to '.$strDate.' ...');
return $strDate;
}