A wrapper class to php DateTime class wich aims to simplify lots of common operations with dates and isolates programmers to be aware of time formats and php date and time internals.
Mauro Caffaratto
licensed under the MIT and GPL licenses
Date_Wrapper is a class that wraps an internal DateTime object, that has a cleaner interface with a bunch of methods that isolates user to be aware about datetime formats and period time formats.
Most functions are chainable.
__toString method is provided based on an output format, which defaults to timestamp.
forge() is a chainable static constructor.
returns a new static instance
returns an internal DateTime object, which is commonly used to make all the date and time operations.
returns the object timestamp.
Delegates on inner DateTime format() method.
Returns the year with 4 digit format.
Returns the month as 2 digit format.
Returns the day as 2 digits day.
Returns the day of the week, sunday beign 0 and saturday 6.
Returns the day of the week with a simple string format, like 'SUN' or 'MON'
Returns the hour from 00 to 23
Returns the minute from 00 to 59
Returns the second from 00 to 59
Returns if the date is past. If $strict, returns if the time is past, with a resolution of seconds.
Returns if the date is future. If $strict, returns if the time is past, with a resolution of seconds.
Adds $days days to the date internally.
Substracts $days days form the date internally.
Adds $months months to the date internally.
Substracts $months months form the date internally.
Adds $years years to the date internally.
Substracts $years years form the date internally.
Adds $hours hours to the date internally.
Substracts $hours hours form the date internally.
Adds $minutes minutes to the date internally.
Substracts $minutes minutes form the date internally.
Adds $seconds seconds to the date internally.
Substracts $seconds seconds form the date internally.
Delegates to inner DateTime sub() method. Both a DateInterval or a string to construct a DateInterval can be passed as paramenter.
Delegates to inner DateTime add() method. Both a DateInterval or a string to construct a DateInterval can be passed as paramenter.
Returns wether $this->get_year() and provided Date year are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_month() and provided Date month are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_day() and provided Date day are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_hour and provided Date hour are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_minute and provided Date minute are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_second and provided Date second are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this->get_timestamp and provided Date timestamp are equals. Both DateTime and Date-Wrapper can be passed as parameter.
Returns wether $this is equal to $date until certain $granularity. Both DateTime and Date-Wrapper can be passed as parameter.
Performs a $do function iterating between $this and $date.
$do function has a ( $key , $date_time , $begin , $end ) signature, where $key is the DatePeriod used to iterate
key, $dt is the DatePeriod DateTime in every iteration, $begin is the older of the two Date_Wrapper passed to iterate, and
$end is the future Date_Wrapper object.
Only Date_Wrapper can be passed as $date.
Method is not chainable.
##Tests
composer update
./vendor/bin/phpunit