PHP Classes

File: README.textile

Recommend this page to a friend!
  Classes of Morshed Alam   A DateTime Helper   README.textile   Download  
File: README.textile
Role: Documentation
Content type: text/plain
Description: Documentation
Class: A DateTime Helper
Get the difference between times in English
Author: By
Last change: Update of README.textile
Date: 6 months ago
Size: 2,709 bytes
 

Contents

Class file image Download
h3. DateTime helper Provide time details either as an array or an object and difference between times in words, timestamps and an object. Also, return a new time adding time intervals in days, week, month, etc.. "View Demo":http://www.scripts.morshed-alam.com/date_time_helper/ :: "Try it out and Rate on phpclasses.org":http://www.phpclasses.org/package/7807-PHP-Get-the-difference-between-times-in-English.html h6. Uses <pre> require 'date_time_helper.php'; // Instance of DateTime helper class // By default helper class work with current date time $dth = new DateTimeHelper(); </pre> h6. Date Time parts <pre> $dth->year(); $dth->month(); $dth->day(); $dth->hours(); $dth->minutes(); $dth->seconds(); //2013, 6, 24, 4, 51, 3 </pre> h6. DateTime details as an object <pre> $dth->time_details $dth->toArray('2011-03-01 10:10:10'); //stdClass Object ( [y] => 2013 [m] => 6 [d] => 24 [h] => 5 [i] => 15 [s] => 16 //[day_position] => 2 [week_of_the_month] => 4 ) </pre> h6. Date Time difference <pre> $dth->differenceAsObject($date); //DateInterval Object ( [y] => 2 [m] => 3 [d] => 23 [h] => 7 [i] => 5 [s] => 6 //[invert] => 1 [days] => 846 ) $dth->differenceAsWords('2011-03-01 10:00:10'); //about 2 years 3 months 23 days 7 hours 5 minutes 6 seconds ago </pre> h6. Repeat date time <pre> $dth->nextRepeatDate($date, -5, 'i'); // 2011-03-01 10:05:10 < -5 minutes $dth->nextRepeatDate($date, 5, 'i'); // 2011-03-01 10:15:10 < +5 minutes $dth->nextRepeatDate($date, -5, 'h'); // 2011-03-01 05:10:10 < -5 hours $dth->nextRepeatDate($date, 5, 'h'); // 2011-03-01 03:10:10 < +5 hours $dth->nextRepeatDate($date, -5, 'd'); // 2011-02-24 10:10:10 < -5 days $dth->nextRepeatDate($date, 5, 'd'); // 2011-03-06 10:10:10 < +5 days $dth->nextRepeatDate($date, -5, 'w'); // 2011-01-25 10:10:10 < -5 weeks $dth->nextRepeatDate($date, 5, 'w'); // 2011-04-05 10:10:10 < +5 weeks $dth->nextRepeatDate($date, -5, 'm'); // 2010-10-01 10:10:10 < -5 months $dth->nextRepeatDate($date, 5, 'm'); // 2011-08-01 10:10:10 < +5 months $dth->nextRepeatDate($date, -5, 'y'); // 2006-03-01 10:10:10 < -5 years $dth->nextRepeatDate($date, -5, 'y'); // 2016-03-01 10:10:10 < +5 years </pre> h6. Testing - Download "SimpleTest":http://www.simpletest.org/en/download.html suit and place it to document root directory. - Run unit_test.php - Run date_time_helper.test.php or index.php h6. Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request