Download the PHP package octava/opening-hours without Composer
On this page you can find all versions of the php package octava/opening-hours. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download octava/opening-hours
More information about octava/opening-hours
Files in octava/opening-hours
Package opening-hours
Short Description A helper to query and format a set of opening hours, clone of spatie/opening-hours
License MIT
Homepage https://github.com/spatie/opening-hours
Informations about the package opening-hours
A helper to query and format a set of opening hours
With spatie/opening-hours
you create an object that describes a business' opening hours, which you can query for open
or closed
on days or specific dates, or use to present the times per day.
A set of opening hours is created by passing in a regular schedule, and a list of exceptions.
The object can be queried for a day in the week, which will return a result based on the regular schedule:
It can also be queried for a specific date and time:
It can also return arrays of opening hours for a week or a day:
Read the usage section for the full api.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Postcardware
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
The best postcards will get published on the open source page on our website.
Installation
You can install the package via composer:
Usage
The package should only be used through the OpeningHours
class. There are also three value object classes used throughout, Time
, which represents a single time, TimeRange
, which represents a period with a start and an end, and openingHoursForDay
, which represents a set of TimeRange
s which can't overlap.
Spatie\OpeningHours\OpeningHours
OpeningHours::create(array $data): Spatie\OpeningHours\OpeningHours
Static factory method to fill the set of opening hours.
Not all days are mandatory, if a day is missing, it will be set as closed.
OpeningHours::fill(array $data): Spatie\OpeningHours\OpeningHours
The same as create
, but non-static.
OpeningHours::forWeek(): Spatie\OpeningHours\OpeningHoursForDay[]
Returns an array of OpeningHoursForDay
objects for a regular week.
OpeningHours::forDay(string $day): Spatie\OpeningHours\OpeningHoursForDay
Returns an OpeningHoursForDay
object for a regular day. A day is lowercase string of the english day name.
OpeningHours::forDate(DateTime $dateTime): Spatie\OpeningHours\OpeningHoursForDay
Returns an OpeningHoursForDay
object for a specific date. It looks for an exception on that day, and otherwise it returns the opening hours based on the regular schedule.
OpeningHours::exceptions(): Spatie\OpeningHours\OpeningHoursForDay[]
Returns an array of all OpeningHoursForDay
objects for exceptions, keyed by a Y-m-d
date string.
OpeningHours::isOpenOn(string $day): bool
Checks if the business is op on a day in the regular schedule.
OpeningHours::isClosedOn(string $day): bool
Checks if the business is closed on a day in the regular schedule.
OpeningHours::isOpenAt(DateTime $dateTime): bool
Checks if the business is open on a specific day, at a specific time.
OpeningHours::isClosedAt(DateTime $dateTime): bool
Checks if the business is closed on a specific day, at a specific time.
OpeningHours::isOpen(): bool
Checks if the business is open right now.
OpeningHours::isClosed(): bool
Checks if the business is closed right now.
Spatie\OpeningHours\OpeningHoursForDay
This class is meant as read-only. It implements ArrayAccess
, Countable
and IteratorAggregate
so you can process the list of TimeRange
s in an array-like way.
Spatie\OpeningHours\TimeRange
Value object describing a period with a start and an end time. Can be casted to a string in a H:i-H:i
format.
Spatie\OpeningHours\Time
Value object describing a single time. Can be casted to a string in a H:i
format.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Sebastian De Deyne
- All Contributors
About Spatie
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.