RE: [PEAR-DEV] Date.php and Calc.php Updates

From: Date: Wed, 05 Feb 2003 12:17:45 +0000
Subject: RE: [PEAR-DEV] Date.php and Calc.php Updates
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-12985@lists.php.net to get a copy of this message
> > DATE_FORMAT_US (maybe should be NORTHAMERICA or AMERICAS?) > Please, *not* AMERICAS, at least in Argentina we use UK format (and I > think, but not sure, most Southamerica's countries use this formats too). > Point taken... Thought making date formats country specific is a bad idea all round (that's why there's ISO!) so have added generic formats, see below. I've made some more changes / bugfixes, here is a revised summary Based on files from cvs.php.net / pear / Date as of 04-FEB-2003 GMT Revised files 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. Calc.php ======== Modified function defaultCentury to handle years of 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 given a 1 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 two new formats DD/MM/YYYY HH:MM:SS (also handles . and - as date element seperators) MM/DD/YYYY HH:MM:SS (also handles . and - as date element seperators) new constants for above are DATE_FORMAT_DMY DATE_FORMAT_MDY Added... Date::isValidDate - wrapper for Date_Calc::isValidDate Date::getFutureDate - wrapper for Date_Calc::addDays Date::getPastDate - wrapper for Date_Calc::subtractDays Date::difference - wrapper for Date_Calc::dateDiff Date::getDatePart - returns requested element(s) in format required (subset of format really) New Constants for Date::getDatePart DATE_PART_DATE DATE_PART_TIME12 DATE_PART_TIME24 DATE_PART_YEAR2 DATE_PART_YEAR4 DATE_PART_MONTH DATE_PART_DAY DATE_PART_HOUR12 DATE_PART_HOUR24 DATE_PART_MINUTE DATE_PART_SECOND DATE_PART_RAW_TZ_OFFSET DATE_PART_DST_TZ_OFFSET Century Handling... Several bits to handle badly formed years in dates (3 digit years) New functions... Date::magicCentury - wrapper for Date_Calc::defaultCentury Date::setMagicCenturyFlag - Set flag to turn on/off use of magicCentury function Date::getMagicCenturyFlag - get current magicCentury Setting Constants for magicCentury Handling OFF ON New Class Property (flag for magic Century) var $magicCentury; Date Seperator... Only affects dates of formats DATE_FORMAT_DMY and DATE_FORMAT_MDY Doesn't change behaviour of Date::format with the %D parameter either New class property to specify date seperator character var $dateSeperator; New Functions for Date Seperator... Date::setDateSeperator - Set the char used for seperating date elements Date::getDateSeperator - Get the char used for seperating date elements New Constants for Date Seperator... define('DATE_SEPERATOR_SLASH', '/'); define('DATE_SEPERATOR_HYPHEN', '-'); define('DATE_SEPERATOR_DOT', '.'); Constructor altered... Set magicCentury off by default ensures backwards compatibility Set dateSeperator set to DATE_SEPERATOR_SLASH by default Date::setDate altered Detects whether or not to run $this->year property through magicCentury or not Does str_replace on date to change -'s or .'s in to /'s for parsing Any REGEXperts available to help change the multiple str_replace calls to a regex ? Date::getDate altered Uses dateSeperator if date format is DATE_FORMAT_DMY and DATE_FORMAT_MDY Phew! must get CVS up and running so I can just do a diff (;oD Feel free to comment and / or alter the code Regards Dean Urmson Mistral Networks Management Ltd (please ignore the out of date website)

« previous php.pear.dev (#12985) next »