Date: additional ISO format support
| From: | Marshall Roch | Date: | Mon, 06 Oct 2003 00:38:54 +0000 |
| Subject: | Date: additional ISO format support | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-22390@lists.php.net to get a copy of this message | ||
I've finally got working support for additional ISO 8601 formats for
Date. It now can input and output:
DATE_FORMAT_ISO: YYYY-MM-DD HH:MM:SS (already exists)
DATE_FORMAT_ISO_BASIC: YYYYMMDDTHHMMSS-HHMM (new)
DATE_FORMAT_ISO_EXTENDED: YYYY-MM-DDTHH:MM:SS-HH:MM (new)
DATE_FORMAT_TIMESTAMP: YYYYMMDDHHMMSS (already exists)
DATE_FORMAT_UNIXTIME: <secs> (already exists)
Several points:
o All 3 ISO formats are basically the same, and as such, can be parsed
with one regex (more efficient than testing for each format individually).
o "Basic" and "Extended" come from the ISO spec. I couldn't find names
for these formats in Perl.
o Each DATE_FORMAT_* constant specifies a different output format. Even
though the /parser/ doesn't differentiate between the 3 ISO formats, the
builder does.
o To support timezone offsets, I added a toUTCbyOffset() method. Since
Date can't look up a timestamp by an offset, I had to convert the
datetime to UTC.
Unit Test:
o To test my changes, I began a PHPUnit test for Date.php. It is not
complete, but it checks enough methods to be sure that the new date
formats work.
Fixed bugs:
o I found two bugs while writing the unit test. See the bug tracker[1]
o Possible bug: the current Date's regexps do not make sure that the
date string contains only a date. I've added ^ and $ to make sure of this.
Attachments:
o Date-ISO.diff - adds date formats and fixes 2 bugs
o testunit_date.php - goes in the tests/ folder, PHPUnit test for Date
o testunit.php - goes in tests/, displays Date and Date_Span unit tests
--
Marshall Roch
[1]
http://pear.php.net/bugs/search.php?cmd=display&status=Open&bug_type[]=Date