Skip to content
/ date Public

Simple date implementation of ISO 8601 standard.

Notifications You must be signed in to change notification settings

robier/date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Date

Simple date implementation of ISO 8601 standard.

Build Status Test Coverage

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 date
  • Date\Factory - factory for creating Date object in different ways
  • Date\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);

About

Simple date implementation of ISO 8601 standard.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published