View Single Post
Old 01-18-2008, 02:17 AM   #1 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Arrow Need more ideas for date and time class

I'm writing a new date and time class. It'll bring all of PHP's inconsistencies when it comes to date and time together. I've written the main chunk of it, and as you can see from the examples below, I've done quite a lot. You'll also see that I've taken the method chaining approach.

However, is there anything else anybody would like to see in a date and time class? Hopefully I can make this awesome enough to help people out with date and time - it's clearly one of those areas where there are a lot of functions all over the place, different formats of dates, et cetera.

php Code:
/* Get day in EST */
echo $pDateTime->date(mktime())->toEST()->getDay();

/* Check if day is a weekend */
echo $pDateTime->date(mktime())->isWeekend() ? 'Yes' : 'No';

/* Check if date is valid */
echo $pDateTime->date('30th February 2008')->isDate() ? 'Yes' : 'No';

/* Custom format output */
echo $pDateTime->date(mktime())->toDate('jS M Y');

/* Output MySQL date in BST */
echo $pDateTime->date(mktime())->toBST()->toMySQLDate();

/* Days until Christmas 2009 */
echo $pDateTime->date(mktime())->untilChristmas(2009)->inDays();

/* Difference in hours between GMT and EST */
$iTargetDate = $pDateTime->date(mktime())->toGMT()->toTimestamp();
echo $pDateTime->date(mktime())->toEST()->until($iTargetDate)->inHours();
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote