omitobisam/carbonate

Carbonate, more muscle to Carbon datetime wrapper

2.0.0 2022-08-30 10:31 UTC

This package is auto-updated.

Last update: 2024-11-29 06:09:43 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version Monthly Downloads

Carbonate - a muscle to PHP Carbon with Collections

- dev-master or bleeding edge

Installation

  • composer require omitobisam/carbonate

If the above does not work then simply include the latest release version as in:

  • composer require omitobisam/carbonate ^0.2.1

For the dev-master simply change the version to dev-master

Another option is to clone the dev-master branch and you can have the bleeding version

Requirements

Minimum: PHP 5.6.4

Usage:

$mydate = new Carbonate('2017-09-01');
$enddate = new Carbonate('2017-10-30);

Get WeekendDates within two dates

$result = $mydate->everyWeekendDays($enddate);

//
/*
* Result - A collection of dates in the weekend
*/
//

Illuminate\Support\Collection Object ( [items:protected] => Array ( 
[0] => Carbonate\Carbonate Object ( [date] => 2017-09-02 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) 
[1] => Carbonate\Carbonate Object ( [date] => 2017-09-03 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) 
[2] => Carbonate\Carbonate Object ( [date] => 2017-09-09 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC )  
.......

Collections method can be further used on the result e.g

// Verify if the last Carbon instance is actually weekend

$mydate->everyWeekendDays($enddate)->last()->isWeekend();

The result of the operations is shown as transformed from Carbon/Carbonate object to string using stringify()

Carbonate::stringify($mydate->everyWeekendDays($enddate));

//
/*
* Result - A collection of dates in the weekends as string
*/
//

Illuminate\Support\Collection Object ( [items:protected] => Array ( 
[0] => 2017-09-02 00:00:00 
[1] => 2017-09-03 00:00:00 
[2] => 2017-09-09 00:00:00 
[3] => 2017-09-10 00:00:00 
[4] => 2017-09-16 00:00:00 
[5] => 2017-09-17 00:00:00 
[6] => 2017-09-23 00:00:00 
[7] => 2017-09-24 00:00:00 
[8] => 2017-09-30 00:00:00 
[9] => 2017-10-01 00:00:00 
[10] => 2017-10-07 00:00:00 
[11] => 2017-10-08 00:00:00 
[12] => 2017-10-14 00:00:00 
[13] => 2017-10-15 00:00:00 
[14] => 2017-10-21 00:00:00 
[15] => 2017-10-22 00:00:00 
[16] => 2017-10-28 00:00:00 
[17] => 2017-10-29 00:00:00 ) )

A string of dates can be converted whole into Carbonate/Carbon instances:

Carbonate::carbonate(['today', 'tomorrow', '2017-10-30']);


Illuminate\Support\Collection Object ( [items:protected] => Array ( 
[0] => Carbonate\Carbonate Object ( [date] => 2017-10-21 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) 
[1] => Carbonate\Carbonate Object ( [date] => 2017-10-22 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) 
[2] => Carbonate\Carbonate Object ( [date] => 2017-10-30 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) ) )

Other methods

$mydate->thisMonth();
$mydate->getDatesOfDaysInMonth(['Monday', 'Saturday']);
$mydate->everyWeekDays();
$mydate->everyDay('Monday');
$mydate->random(2);
$mydate->randomOne();
$mydate->anyMonday();
$mydate->anyTuesday();
$mydate->anyWednesday();
$mydate->anyThursday();
$mydate->anyFriday();
$mydate->anySaturday();
$mydate->anySunday();
$mydate->any();
$mydate->anyOne('Monday');
$mydate->stringify([Carbonate::now(), Carbonate::now()->addDay(1)]);
$mydate->carbonate(['today', 'tomorrow']);
$mydate->weekends(Carbonate::now()->addDay(7));

Info

Contributions