PEAR is archived and read-only

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

Home » Date and Time » Calendar » Bug #1880

Get month/day values with leading zero

Details

Request #1880Get month/day values with leading zero
Submitted2004-07-15 08:11 UTC
Fromroehr at zilleon dot com
Assignedquipo
StatusClosed
PackageCalendar
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-07-15 08:11 UTC] roehr at zilleon dot com

Description:
------------
First of all thanks for this fantastic package!

Unfortunately, I couldn't find a way to retrieve a month/day value from a Calendar or Calendar derived object with a leading zero.
This would make building ISO date formats (like MySQLs date column) from individual values much easier.

I also asked on pear-general if this feature exists but didn't receive any answer.

Therefore I would like to request the addition of a fifth return type for Calendar::returnValue() named 'string' that returns one-digit values with a leading zero so that 1 becomes 01, 2 becomes 02 and so on.

See below for my code proposal. Thanks!

Best regards,
Torsten Roehr

Reproduce code:
---------------
Starting from line 290 in Calendar.php:

function returnValue($returnType, $format, $stamp, $default)
{
switch (strtolower($format)) {
case 'int':
return $default;
case 'array':
return $this->toArray($stamp);
break;
case 'object':
require_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp($returnType,$stamp);
break;
// start new code
case 'string':
return (strlen($default) == 1) ? '0' . $default : $default;
break;
// end new code
case 'timestamp':
default:
return $stamp;
break;
}
}

I added three lines for case 'string'. Of course all doc blocks that list the possible return types would have to be updated.

I hope you find this addition useful. Thanks.