Download the PHP package ruslanovich111/date-converter without Composer
On this page you can find all versions of the php package ruslanovich111/date-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package date-converter
Description
The library provides extended functionality for working with dates.
- converting date rows "The 13th of Mar. 1999", "Mar. 2022" to objects.
- converting date rows in different languages "8 März 2023"
- converting date intervals "13th of Mar. 1999 - 8 März 2023"
- converting date sequences "The 12th of April 2022; 8 März 2023"
- search dates in a text in your language...
The library solves all these problems.
Versions
- There is code for php8.1 in the master branch (tags 1.0.*)
- There is code for php8.0 in the master-php8.0 branch (tags 1.1.*)
Configuration
Create ArrayPatternStorage.\
The object takes config array of a strictly defined format:
- The
patternsfield should contain regular expressions for dates. - The
monthsfield should contain regular expressions for months. There should be exactly 12 of them.
The library automatically substitutes regular expressions:
$day = [0-9]{1,2}, $year = [0-9]{4}, $month = January|Jan\.|February|....
Convertation
All possible examples of using the library are in the examples folder.\ For example, in ./examples/simple_date/test.php the simple convertation is described:
The convertToDate method will return a DateModel object since the string "12th February 2022" matches the first pattern in
configuration file.\
If you pass a string that does not match any of the patterns, then an Exception will be thrown.\
The order of the patterns in the configuration is important because the convertToDate method returns a DateModel based on the first matching pattern!
Advanced options
Interval convertation: interval-convertation\ Sequence convertation: secuence-convertation\ Multiple pattern storages: multiple-storages
Search
The library provides two search strategies:
- search with replacement
- search with repetitions
Examples of using search are described in the folder examples/search.
Next, let's explain the differences.\
Let the input row be given:\
It was sunny outside on the 12th of April 2022, 13 April 2022 and the 17th of April 2021
Search with replacement
- find all dates for the input corresponding to the first pattern, replace with $pattern_1, save the transformed row:\
It was sunny outside on $pattern_1, 13 April 2022 and $pattern_1.\ The dates for pattern 1 are stored in the TextAllPatternMatches model. - In the transformed row (with $pattern_1) we find the dates for the pattern 2, replace it with $pattern_2, save the transformed row:\
It was sunny outside on $pattern_1, $pattern_2 and $pattern_1.\ The dates for pattern 2 are stored in the TextAllPatternMatches model. - etc...
For this strategy, the order of the patterns in the configuration is important!
Search with repetitions
- find all dates for the input corresponding to the first pattern, replace with $pattern_1, save the transformed row:\
It was sunny outside on $pattern_1, 13 April 2022 and $pattern_1.\ The dates for pattern 1 are stored in the TextPattern model. - again we take the input row and find the dates corresponding to pattern 2, replace it with $pattern_2, save string:\
It was sunny outside on the 12th of April 2022, $pattern_2 and the 17th of April 2021,\ The dates for pattern 2 are stored in the TextPattern model. - etc...
Thus the TextPatternSequence is fill with the TextPattern models. The order is not important for this strategy.
Advanced options
Interval search: interval-search
All versions of date-converter with dependencies
ext-mbstring Version *