Documentation

decode

\Bitrix\Main\Text\DateConverter::decode(
   $text, 
   $limit = 0
);

Static method recognises dates in text.

Parameters

Method Description Available from version
text Text for recognition.
limit Limit for text processing in characters. 0 - no limits. It's recommended to use sensible limit, for example: recognise date only from the first thousand characters.

Three (3) groups of phrases and two (2) groups of modifiers are used for building, based on which recognition is performed:

Relative date Days of week Precise dateDate modifiers Time modifiers
Day after tomorrow Monday11.02After: +hour Morning - 10:00
Tomorrow Tuesday11.02.2013Before: -hour Lunch - 14:00
Today Wednesday11.02.13 - (will be 11.02.2013)Before: -hour Afternoon - 18:00
Yesterday Thursday Evening - 20:00
Day before yesterday Friday
Week Saturday
Weekend Sunday
Month

By mixing elements of groups and modifiers, a compound date can be created, for example: the phrase Remind me on the next midmonth to set a task for you returns the date (for a message, written in April 2007):

2017-05-16 19:00:00

Examples

When you need only the date:

$date = Bitrix\Main\Type\DateTime::createFromText('Remind me on the next midmonth to set a task for you');
$date // DateTime object

When you need more data or all the dates, found inside the text

$results = \Bitrix\Main\Text\DateConverter::decode('Remind me on the next midmonth to set a task for you', 1000);
foreach ($results as $result) // Array with recognition result
{
   $result->getDate(); // Object DateTime
   $result->getText(); // Recognized text to be used for , который можете использовать для замены на действие
   $result->getTextPosition(); // Recognized text start
   $result->getTextLength(); //  Recognized text length
   $result->getType(); // Recognized main type
   $result->getMetrics(); // Main metrics (day of week, week and etc.)
   $result->getMetricModifier(); // Main metrics modifiers (before, after, time)
}


© «Bitrix24», 2001-2022
Up