Download the PHP package letsjump/workday-helper-php without Composer
On this page you can find all versions of the php package letsjump/workday-helper-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package workday-helper-php
WorkdayHelper
Count workdays and list holiday events in a range of dates with PHP taking care of public holidays and other custom closing days.
Inspired by Massimo Simonini getWorkdays() Gist. @see https://gist.github.com/massiws/9593008
Benefits and features:
- you can specify a range of working days in a week (from Monday to Sunday);
- you can add custom holidays and business closures, for example as a result of a database query;
- it returns a calendar of holidays for that specific range of dates;
- you can use your custom recursive holiday calendar (see
$publicHolidays
); - it takes care of the timezone of your application;
- it automatically calculates Easter, and Easter mondays taking care of the timezone (requires PHP with
ext-calendar
);
Requirements
PHP 5.6.0 and later
Composer
The preferred way to install this extension is through composer.
Either run
or add
to the require
section of your composer.json.
Manual Installation
If you do not wish to use Composer, you can download the latest release.
Dependencies
PHP ext-calendar
To automatically calculate Easter dates, you have to compile PHP with --enable-calendar
. See ext-calendar. You can refer to this Stack Overflow question if you are in a Docker environment.
If your PHP isn't compiled with ext-calendar and if you cannot compile it, please set $calculateEaster
to false
otherwhise WorkingdayHelper will throw an exception.
Usage:
-
Count the days worked in January while working from Monday to Friday, taking care of public holidays:
-
count the day worked in april while working Monday, Wednesday and Friday, taking care of public holidays:
-
Add a strike to the custom closing days
- Get the calendar with all the closing days for a specific date interval
Add custom closings
Custom closure is an array of events. Each event is an array with this configuration:
key | value | mandatory |
---|---|---|
date | date in Y-m-d format | yes |
event | a string representing the name of the closing | yes |
options | a string or an array passed as is to the holiday calendar. It may contain information such as event_id, user_id, html attributes, etc.. Please remember that data are passed as they are so, to prevent malicious injection attacks, consider the use of a string purifier function | no |
example
Replace the default recursive holiday calendar
The default recursive holiday calendar is an array of events. Each event is an array with this configuration:
key | value | mandatory |
---|---|---|
m-d | the date must be in m-d format | yes |
event | a string representing the name of the holiday | yes |
options | a string or an array passed as is to the holiday calendar. It may contain information such as event_id, user_id, html attributes, etc.. Please remember that data are passed as they are so, to prevent malicious injection attacks, consider the use of a string purifier function | no |
example
Holiday calendar
The holiday calendar returns a list of holidays for the working days in the given date range. So if you want to retrive all the closing days in that date range you should set all the days of the week into the $workingDays Array E.G. $myWorkDay->workingDays[0,1,2,3,4,5,6].
The output is an array of events. Each array has the unix timestamp of the holiday as key and contains:
key | value | |
---|---|---|
unixTimestamp | the unix timestamp of the event | |
date | the readable date of the event (you can format it with the parameter $outputFormat |
|
event | the name of the event type | public or custom depending if it is a publicHoliday or a customClosing. |
options | a string or an array of user custom options |
Example
Side notes
The recursive holiday and the default date format are localized for Italy. I know it's not the right way to work, but I need to quickly develop an application for a customer. If you want to use your localization, please refer to Replace the default recursive holiday calendar. If you plan to use intensively in your application, you may extend the base class and configure there the basic properties.
Please report any bug or whishes into the apposite issue tracker