ludovicm67/superdate

Nice methods to know if the specified date is on a weekend/weekday or holiday (for Alsace, France), and some other cool stuff

v2.0.0 2021-01-17 14:27 UTC

This package is auto-updated.

Last update: 2024-05-19 23:02:16 UTC


README

Some useful functions for working with dates

Latest Stable Version Total Downloads Coverage Status License

Installation

Just run the following command: composer require ludovicm67/superdate to add it to your PHP project!

Getting started

If you installed using composer, you can now create a file with the following code:

<?php

// import here the composer autoloader
require('./vendor/autoload.php');

// use the namespace for this library
use ludovicm67\SuperDate\Date;

// your code below...

Create a Date object

Many ways to initialize the object.

For example:

// value: today
$date = new Date();
$date = new Date(null);

// value: specified date
$date = new Date("2019-03-21");

All days from one date to an other date

Get an array of all days from the current date to an other one.

Example:

$date = new Date("2019-03-21");
$allDaysTo = $date->allDaysTo("2019-04-03");

// $allDaysTo will be an array containing all 14 days
// between 2019-03-21 and 2019-04-03 included

Is it a week day or a weekend day?

$date->isWeekDay(); // true if between monday and friday, false if saturday or sunday
$date->isWeekEnd(); // false if between monday and friday, true if saturday or sunday

Is it a holiday day?

Based on Alsace, France holidays.

Usage:

$date->isHoliday(); // true if holiday, false if not

Want to contribute?

Feel free to fork, commit and open a pull-request.

Or just open an issue here: https://github.com/ludovicm67/php-superdate/issues.