Download the PHP package hnesk/todate without Composer
On this page you can find all versions of the php package hnesk/todate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package todate
Short Description An easy to use DSL for date expression
License GPL-3.0
Homepage https://github.com/hnesk/ToDate
Informations about the package todate
ToDate
A PHP date expression library with a corresponding domain specific language (DSL)
Describing DateConditions as strings (DSL)
This library contains a DSL (domain specific language) to describe complex date scenarios as simple strings. This DSL expressions get parsed to a tree of expressions, that can be evaluated for any given date.
Sounds complicated? No it isn't.
Imagine your garbage gets picked up, every first monday each month. How would communicate that fact to a machine?
What about every first and third monday each month?
What about every second and last monday each month? (using pythons notion of negative numbers as counting from the end).
Ok, let's say every monday, but not if its Easter monday (constant Easter
means Easter sunday)
Or whit monday (50 days after Easter sunday), independence day, or christmas?
All date conditions in the ToDate/Condition namespace can be created with the corresponding DSL string syntax
DSL Building Blocks
All of these conditions are mapped to single \ToDate\Condition\AbstractDateCondition
instance.
Date
Just one fixed date, example only on Independence Day 2021
Easter based date conditions
Every whit sunday
DateModulo
Every 2 weeks (14 days) starting from 2021-03-12
DayAndMonth
Every independence day
DayOfMonth
Every 1st and 15th each month
or every 1st till 9th each month
DayOfWeek
Every saturday and sunday
DayOfWeekMonth
Every 1st and 3rd monday
Every 2nd and last (=-1 like in python) monday
Month
In the summertime
Year
The corona years
Combinig Conditions with logical operators
All conditions can be combined with AND
, OR
and NOT
to form complex date conditions.
Examples
see also the executable examples