| Recommend this page to a friend! |
| Info | Documentation | Reputation | Support forum | Blog | Links |
| Ratings | Unique User Downloads | Download Rankings | ||||
| Not enough user ratings | Total: 190 | All time: 8,596 This week: 660 | ||||
| Version | License | PHP version | Categories | |||
| time-parser 1.0 | BSD License | 5.3 | PHP 5, Time and Date, Parsers |
| Description | Author | |||
This class can parse time in natural language and multiple idioms. Innovation Award
|
|
TimeParser - is a parser for date and time written in natural language for PHP.
Parse some input from user and receive a `DateTime` object.
$datetime = wapmorgan\TimeParser\TimeParser::parse(fgets(STDIN), 'all');
Second arg is a language. Applicable values: * 'all' - scan for all available languages. Use it when you can not predict user's preferred language. * 'english' - scan only as english time. * array('english', 'russian') - scan as english and then the rest as russian time. * 'nonexistent-language' - force scan with system strtotime() function. In case of strtotime() scan failure, current DateTime will be returned.
в 15:12:13 в Ñледующий понедельник в Ñледующем году в феврале через 15 чаÑов через 10 минут через 11 Ñекунд через 5 лет через 2 недели через 1 день через 10 меÑÑцев
at 15:12:13 next monday next year in february in 15 hours in 10 minutes in 11 seconds in 5 years in 2 weeks in 1 day in 10 months
They both will be parsed and result DateTime will contain right date:
Sun, 03 Oct 2021 06:22:24 +0400
For this moment four languages supported: Russian, English, French and German. Two languages support is in progress: Chinese, Spanish.
Their rules are in rules catalog so you can improve TimeParser by adding new language or by improving existing one.
For developing reasons you may would like to see process of parsing. To do this call related methods:
TimeParser::enableDebug();
// and
TimeParser::disableDebug();
To understand, how it works, look at substrings separately:
If you set third argument of parse() to true, TimeParser will be able to parse alphabetic values:
If you want to disallow users use words instead of numbers, save default settings or set third argument of parse() to false. In this case alphabetic values will not be parsed.
Numbers up to 20 are available to use.
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Doc. | Documentation | |||
| Test | Unit test script | |||
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 100% |
|
|
| Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.