Download the PHP package phpexperts/workday-planner without Composer
On this page you can find all versions of the php package phpexperts/workday-planner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpexperts/workday-planner
More information about phpexperts/workday-planner
Files in phpexperts/workday-planner
Package workday-planner
Short Description Given a date range, this will give you all of the workdays for that country.
License MIT
Homepage https://github.com/phpexpertsinc/workday-planner
Informations about the package workday-planner
The PHP Workday Planner
Installation
Run composer require phpexperts/workday-planner
The Problem
Imagine that you have to schedule a task to run every workday in your country over a given time period.
In order to do this, you first have to figure out what the workdays are, and the weekends. Simple enough, right? But then you remember: "Hey, what about Christmas? and all those other holidays?"
So you dutifully go about detecting those, too. Only to have your clients complaining on the Monday after the Fourth of July. Because, you see, at least in the United States, holidays that occur on Saturdays are observed on the previous Friday, while holidays that occur on Sundays are observed on the next Monday.
The Solution
With this package, all of these technicalities are handled for you. You give it a date range, and it will dutifully spit out the workdays, keeping in mind both the actual and observed U.S. national holidays common to most employers.
Ad-hoc Workday Verification
Floating Holidays
Some holidays are based upon a certain day of the month, instead of a fixed date. These are called "floating holidays".
The date spec looks like this for Thanksgiving Day:
Examples:
Observerable Holidays
Ad-hoc Holiday Verification
Access to the Workdays
There are several ways to access the workdays.
The Workday Planner can be accessed like an array, or as an iterator, or you can just get a simple array of all the workday dates.
Simple access
As an iterator
As an array
Manually remove a workday
Workdays can be manually removed, per your policies:
Behavior Documentation
The project currently has 100% code coverage via unit tests.
Here is the behavior documentation, generated by PHPUnit's testdox:
HolidayDetector
- Can parse fixed holiday dates
- Can parse floating holiday dates
- Can determine if a date is a holiday
- Shows error for unimplemented country
- Shows error for invalid data
- Shows error for invalid holiday spec
- Properly handles unknown holidays
- Will report friday as the observed day for saturday holidays
- Will report friday as the observed day for sunday holidays
WorkdayDetector
- Can determine if a date is a workday
WorkdayPlanner
- Will create a date range of workdays
- Will properly offset saturday holidays
- Will properly offset sunday holidays
- Can iterate through each date
- The number of workdays is countable
- Can access dates via the array operator with a numeric index
- Can access dates via the array operator with a date index
- Can use numeric isset on a workday
- Can use date isset on a workday
- Can remove a work day via unset
- Properly handles a start date later than the end date
- Properly handles a start date equal to the end date
- Properly handles invalid dates
- Wont allow manually adding workdays
Credits
Created by Theodore R. Smith [email protected], mostly in one day.
A PHP Experts, Inc., project.