Date.php and Calc.php Updates
| From: | Dean Urmson | Date: | Wed, 05 Feb 2003 01:28:41 +0000 |
| Subject: | Date.php and Calc.php Updates | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-12974@lists.php.net to get a copy of this message | ||
Hi All,
First time contributing to Open Source so...
I have some updates to the Date package in PEAR, the changes have been done
on the latest files from cvs.php.net / pear / Date as of 04-FEB-2003 GMT and
can be downloaded from http://www.mistral-networks.co.uk/dl/pearDate.zip
I've added one file
test/test_date.php
which is the start of a test script to put the Date package through it's
paces.
I've updated two files
Date.php and Date/Calc.php
A summary of changes are below.
I guess not everyone will want the UK, EURO and US date support in there (I
do) but there are other valuable additions.
Calc.php
========
Modified function defaultCentury to handle years of 1, 2, or 3 digits long
e.g.
given a year of 512 the old version produced 19512, new version returns 0512
given a year of 2000 the old version produced 192000, new version returns
2000
given a 2 digit year, behaviour as per previous version
Added functions
addDays and subtractDays
Similar to nextDay and prevDay but adds an arbitary number of days instead
of just one.
Allows calcs like what is the date 57 days from now or Password Expiry Date
is today plus 32 days.
Date.php
========
Added support for
UK Dates (DD/MM/YYYY HH:MM:SS)
EURO Dates (DD-MM-YYYY HH:MM:SS)
US Dates (MM-DD-YYYY HH:MM:SS)
new constants for above are
DATE_FORMAT_EURO
DATE_FORMAT_UK
DATE_FORMAT_US (maybe should be NORTHAMERICA or AMERICAS?)
Added Functions
isValidDate - wrapper for Date_Calc::isValidDate
getFutureDate - wrapper for Date_Calc::addDays
getPastDate - wrapper for Date_Calc::subtractDays
Several bits to handle badly formed years in dates (1,2, or 3 digit years)
magicCentury - wrapper for Date_Calc::defaultCentury
setMagicCenturyFlag - Set flag to turn on/off use of magicCentury function
getMagicCenturyFlag - get current magicCentury Setting
Constants for magicCentury Handling
OFF
ON
New Class Property (flag for magic Century)
var $magicCentury;
Constructor altered to set magicCentury off by default ensures backwards
compatibility
function setDate
Detects whether or not to run $this->year property through magicCentury or
not
Feel free to comment and / or alter the code
Regards
Dean Urmson
Mistral Networks Management Ltd
(please ignore the out of date website)