ishworkh/navigable-date

Wrapper around php DateTime class
63
Install
composer require ishworkh/navigable-date
Latest Version:v3.0.0
PHP:>=7.0
License:MIT
Last Updated:Feb 25, 2017
Links: GitHub  ·  Packagist
Maintainer: Ishworkh

(PHP) NavigableDate

NavigableDate is a wrapper around core php DateTime class. It encapsulates core class and exposes NavigableDateInterface that provides ways to navigate through a date. It exposes methods like nextDay, nextWeek, previousDay, nextMonth etc, in addition to methods like format, getTimestamp,getOffset, getDifference and getTimezone.

Basic Usage

It can be instantiated with normal new operator but that needs you to manually handle the dependencies (NavigableDate\NavigableDateLocator provides all the dependencies required).

Recommended way to get an instance is through NavigableDateFactory available also in NavigableDateLocator.

   
   $NavigableDate = NavigableDate\NavigableDateLocator::getInstance()
                   ->getNavigableDateFactory()
                   ->create('2016-07-11');
   
   or 
   
   $NavigableDate = NavigableDate\NavigableDateLocator::getInstance()
                   ->getNavigableDateFactory()
                   ->createFromDateTime(new DateTime());
   

Or even easier NavigableDate\NavigableDateFacade is provided for the instantiation.

   $NavigableDate = NavigableDate\NavigableDateFacade::create('2016-07-11');

It includes NavigableDate\NavigableDateServiceProvider to integrate this library to Laravel application. Just include this provider in the lists of service providers. After which type hinting NavigableDate\NavigableDateFactory will resolve into respective factory class responsible for creating new instance of NavigableDate\NavigableDate

Then,

   $NextDay = $NavigableDate->nextDay();
   
   $NextDay->getTimestamp();
   $NextDay->getOffset();
   $NextDay->getTimeZone();
   $NextDay->format('Y-m-d');
   
   $NextNextDay = $NextDay->nextDay(); 
   $NextNextDay->nextMonth();
   
   $resetTime = true;
   $resetDays = true;
   $resetMonths = true;
   
   $NextDay->previousYear($resetTime, $resetDays, $resetMonths);
   
   // $resetTime -> resets time to 00:00:00
   // $resetDays -> resets day of the month to 01 | resets day to start of the week i.e. Monday in case of nextWeek|prevWeek
   // $resetMonths -> resets month of the year to 01
   

Also possible to do previousMonth, nextYear with possibility to reset time, days or months available in corresponding methods.

NOTE: For more details about methods it provides, look into NavigableDate\NavigableDateInterface

Related Packages

hekmatinasser/verta

This Package helps developers to work with Jalali Datetime class for Laravel Fra...

558,880 659
miladr/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dat...

9,627 48
jenssegers/date

A date library to help you work with dates in different languages

11,533,373 1,804
morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dat...

1,292,578 921
p3ym4n/jdate

A simple php date converter from Jalali to Georgian calendar and vice versa.

1,820 10