robier / date
Simple date implementation of ISO 8601 standard
v1.1.0
2017-08-07 08:55 UTC
Requires
- php: ^7.1
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2024-11-13 05:26:28 UTC
README
Simple date implementation of ISO 8601 standard.
Introduction
The Date class follows the ISO 8601 standard for representing date.
Also allows easy getting range of two dates.
Installation
You can install this library with composer.
composer require robier/date
Requirements
This library requires PHP 7.1.
Overview
This library contains of 3 classes:
Date
- representation of actual dateDate\Factory
- factory for creatingDate
object in different waysDate\Range
- generator that represents range between 2 dates
Samples
Creating new instance of Date (various ways how to get date 1991-11-14):
use Robier\Date; $date = new Date(1991, 11, 14); // or $date = Date/Factory::new(1991, 11, 14); // or $date = Date/Factory::dateTime(DateTime::createFromFormat('Y-m-d', '1991-11-14')); // or $date = Date/Factory::string('1991-11-14'); // or $date = Date/Factory::iso(1991, 46, 4);
Get today date:
$today = Date/Factory::today();
Get tomorrows date:
$tomorrow = Date/Factory::tomorrow(); // or $tomorrow = Date/Factory::today()->next();
Get yesterday date:
$yesterday = Date/Factory::yesterday(); // or $yesterday = Date/Factory::today()->previous();
Get any date in future of provided date (ie. 5 days after 1991-11-14):
$date = new Date(1991, 11, 14); $date->next(5);
Get any date in past of provided date (ie. 6 days before 1991-11-14):
$date = new Date(1991, 11, 14); $date->previous(6);
Range between 2 dates (ie. get dates between 1991-11-14 and 1991-12-01):
$start = new Date(1991, 11, 14); $end = new Date(1991, 12, 1); $range = new Date\Range($start, $end); // or $range = $start->to($end);