2017 © Pedro Peláez
 

library datetime

Extends PHP's DateTime class with convenience methods

image

michaelesmith/datetime

Extends PHP's DateTime class with convenience methods

  • Friday, June 27, 2014
  • by michaelesmith
  • Repository
  • 1 Watchers
  • 2 Stars
  • 113 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status SensioLabsInsight, (*1)

README

What is msDateTime?

An extension of the PHP native DateTime object to provide powerful convenience methods., (*2)

Installation

The recommended way to install msDateTime is through composer., (*3)

If you don't have Composer yet, download it following the instructions on http://getcomposer.org/ or just run the following command:, (*4)

curl -s http://getcomposer.org/installer | php

Just create a composer.json file for your project:, (*5)

json { "require": { "michaelesmith/datetime": "*" } }, (*6)

For more info on composer see https://github.com/composer/composer, (*7)

Examples

Basic

$d = new msDateTime('2/5/1980 18:53:37'); //any string you could use with php's native DateTime
var_dump($d->format('l F j @ g:ia')); //any formating accepted by php's date()
// string(27) "Tuesday February 5 @ 6:53pm"
var_dump($d->dump()); //show current timestamp human readable for debugging
// string(31) "Tue, 05 Feb 1980 18:53:37 -0600"

Convenience methods example

$d = new msDateTime();
var_dump($d->modify('-1 year +3 days')->dump());
// string(31) "Thu, 19 Aug 2010 22:38:39 -0500"
var_dump($d->finalDayOfQuarter()->endOfDay()->dump());
// string(31) "Thu, 30 Sep 2010 23:59:59 -0500"
var_dump($d->reset()->dump()); //internal timestamp can be reset to initial
// string(31) "Tue, 16 Aug 2011 22:38:39 -0500"

Complete list of methods

Update

  • public function beginningOfDay()
  • public function endOfDay()
  • public function firstDayOfWeek() //Sets to Sunday
  • public function finalDayOfWeek() //Sets to Saturday
  • public function firstDayOfMonth()
  • public function finalDayOfMonth()
  • public function firstDayOfQuarter()
  • public function finalDayOfQuarter()
  • public function isFinalDayOfQuarter()

Tests

  • public function isBeginningOfDay()
  • public function isEndOfDay()
  • public function isFirstDayOfWeek() //Returns true for Sunday
  • public function isFinalDayOfWeek() //Returns true for Saturday
  • public function isFirstDayOfMonth()
  • public function isFinalDayOfMonth()
  • public function isFirstDayOfQuarter()

Tests around now

  • public function isToday()
  • public function isTomorrow()
  • public function isYesterday()
  • public function isCurrentWeek() //Uses ISO-8601 weeks Monday - Sunday
  • public function isCurrentMonth()
  • public function isCurrentYear()

Miscellaneous

  • public static function create($time = null, $object = null) //Creates a new msDateTime object inline to preserve fluid calls
  • public function __toString() //Returns the current timestamp in "Y-m-d H:i:s" format
  • public function copy()
  • public function compare($msDateTime2) //Compares this object to $msDateTime2 by returning the difference in seconds
  • public function dump() //Outputs the current timestamp in a general format. Should only be used for debugging.
  • public function getQuarter()

The Versions

27/06 2014

dev-master

9999999-dev http://michaelsmithonline.blogspot.com/p/datetime.html

Extends PHP's DateTime class with convenience methods

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

date time datetime

03/08 2012

dev-develop

dev-develop http://michaelsmithonline.blogspot.com/p/datetime.html

Extends PHP's DateTime class with convenience methods

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

date time datetime