TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-18-2008, 02:17 AM   #1 (permalink)
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
Old 01-18-2008, 11:25 AM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Hi mate,

One of the things I've always wanted to see in a date class is a method to compare two dates and return an array of date parts showing the difference.

Also your date() method looks like it can take multiple date formats so it would be handy if you write an add() / sub() method to add or remove to a date.

For example

PHP Code:
<?php

$newDate 
$pDateTime->date('1st February 2008')->add('month'3);
$newDate $pDateTime->date('2008-05-26')->sub('day'20);
If I think of any more I'll let you know.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-18-2008, 02:22 PM   #3 (permalink)
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
Default

Thanks for the suggestion, bud All added!

php Code:
/* Add 3 months to current date and time */
echo $pDateTime->date(mktime())->add('month', 3)->toDate('jS M Y');
__________________
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
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:29 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design