package.xml0000664000175000017500000004213412653700656011315 0ustar janjan Horde_Date_Parser pear.horde.org Horde Date Parser Library for natural-language date parsing, with support for multiple languages and locales Chuck Hagenbuch chuck chuck@horde.org yes Jan Schneider jan jan@horde.org yes 2016-02-01 2.0.5 1.0.0 stable stable LGPL-2.1 * [jan] Mark PHP 7 as supported. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Date pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Support pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 1.0.0alpha1 1.0.0 alpha alpha 2011-03-07 LGPL-2.1 * First alpha release for Horde 4. 1.0.0alpha2 1.0.0 alpha alpha 2011-03-09 LGPL-2.1 * Fix package layout. 1.0.0beta1 1.0.0 beta beta 2011-03-16 LGPL-2.1 * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 LGPL-2.1 * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 LGPL-2.1 * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 LGPL-2.1 * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-11-22 LGPL-2.1 * [jan] Fix tests to work with PHPUnit 3.6. 1.0.2 1.0.0 stable stable 2011-12-06 LGPL-2.1 * [jan] Correctly parse "nacht" in German (Bug #10511). 2.0.0alpha1 1.0.0 alpha stable 2012-07-05 LGPL-2.1 * First alpha release for Horde 5. 2.0.0beta1 1.0.0 beta stable 2012-07-19 LGPL-2.1 * First beta release for Horde 5. 2.0.0 1.0.0 stable stable 2012-10-30 LGPL-2.1 * First stable release for Horde 5. 2.0.1 1.0.0 stable stable 2012-11-19 LGPL-2.1 * [mms] Use new Horde_Test layout. 2.0.2 1.0.0 stable stable 2013-03-05 LGPL-2.1 * [mjr] Fix several parsing bugs (Bug #12006). 2.0.3 1.0.0 stable stable 2015-01-08 LGPL-2.1 * [jan] Add Composer definition. 2.0.4 1.0.0 stable stable 2015-04-28 LGPL-2.1 * [jan] Fix issues with certain locales like Turkish. 2.0.5 1.0.0 stable stable 2016-02-01 LGPL-2.1 * [jan] Mark PHP 7 as supported. Horde_Date_Parser-2.0.5/doc/Horde/Date/Parser/examples/parse.php0000664000175000017500000000056712653700656022536 0ustar janjan 1 ? array() : array('now' => new Horde_Date('2006-08-16 14:00:00')); $d = Horde_Date_Parser::parse($t, $opts); echo "$d\n"; Horde_Date_Parser-2.0.5/doc/Horde/Date/Parser/COPYING0000664000175000017500000005765612653700656020143 0ustar janjan GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Horde_Date_Parser-2.0.5/doc/Horde/Date/Parser/TODO.txt0000664000175000017500000000012112653700656020365 0ustar janjan- Horde_Date_Repeater_Weekday - tests from http://www.datejs.com/test/index.html Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Grabber.php0000664000175000017500000000124312653700656023214 0ustar janjan 'last', '/this/' => 'this', '/next/' => 'next', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForAll($token)) { $token->tag('grabber', $t); } } return $tokens; } public function scanForAll($token) { foreach ($this->scanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Ordinal.php0000664000175000017500000000164712653700656023250 0ustar janjanscanForOrdinals($token))) { $token->tag('ordinal', $t); } if (!is_null($t = $this->scanForDays($token))) { $token->tag('ordinal_day', $t); } } return $tokens; } public function scanForOrdinals($token) { if (preg_match($this->ordinalRegex, $token->word, $matches)) { return (int)$matches[1]; } } public function scanForDays($token) { if (preg_match($this->ordinalDayRegex, $token->word, $matches)) { if ($matches[1] <= 31) { return (int)$matches[1]; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Pointer.php0000664000175000017500000000121712653700656023271 0ustar janjan 'past', '/\bfuture\b/' => 'future', '/\bin\b/' => 'future', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForAll($token)) { $token->tag('pointer', $t); } } return $tokens; } public function scanForAll($token) { foreach ($this->scanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Repeater.php0000664000175000017500000000757012653700656023430 0ustar janjan 'january', '/^feb\.?(ruary)?$/i' => 'february', '/^mar\.?(ch)?$/i' => 'march', '/^apr\.?(il)?$/i' => 'april', '/^may$/i' => 'may', '/^jun\.?e?$/i' => 'june', '/^jul\.?y?$/i' => 'july', '/^aug\.?(ust)?$/i' => 'august', '/^sep\.?(t\.?|tember)?$/i' => 'september', '/^oct\.?(ober)?$/i' => 'october', '/^nov\.?(ember)?$/i' => 'november', '/^dec\.?(ember)?$/i' => 'december', ); public $dayNameScanner = array( '/^m[ou]n(day)?$/i' => 'monday', '/^t(ue|eu|oo|u|)s(day)?$/i' => 'tuesday', '/^tue$/i' => 'tuesday', '/^we(dnes|nds|nns)day$/i' => 'wednesday', '/^wed$/i' => 'wednesday', '/^th(urs|ers)day$/i' => 'thursday', '/^thu$/i' => 'thursday', '/^fr[iy](day)?$/i' => 'friday', '/^sat(t?[ue]rday)?$/i' => 'saturday', '/^su[nm](day)?$/i' => 'sunday', ); public $dayPortionScanner = array( '/^ams?$/i' => 'am', '/^pms?$/i' => 'pm', '/^mornings?$/i' => 'morning', '/^afternoons?$/i' => 'afternoon', '/^evenings?$/i' => 'evening', '/^(night|nite)s?$/i' => 'night', ); public $unitScanner = array( '/^years?$/i' => 'year', '/^seasons?$/i' => 'season', '/^months?$/i' => 'month', '/^fortnights?$/i' => 'fortnight', '/^weeks?$/i' => 'week', '/^weekends?$/i' => 'weekend', '/^days?$/i' => 'day', '/^hours?$/i' => 'hour', '/^minutes?$/i' => 'minute', '/^seconds?$/i' => 'second', ); public $timeRegex = '/^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/'; public function scan($tokens, $options) { foreach ($tokens as &$token) { if ($t = $this->scanForMonthNames($token)) { $token->tag('repeater_month_name', $t); } elseif ($t = $this->scanForDayNames($token)) { $token->tag('repeater_day_name', $t); } elseif ($t = $this->scanForDayPortions($token)) { $token->tag('repeater_day_portion', $t); } elseif ($t = $this->scanForTimes($token, $options)) { $token->tag('repeater_time', $t); } elseif ($t = $this->scanForUnits($token)) { $token->tag(Horde_String::lower(str_replace('Horde_Date_', '', get_class($t))), $t); } } return $tokens; } public function scanForMonthNames($token) { foreach ($this->monthNameScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_MonthName($scannerTag); } } } public function scanForDayNames($token) { foreach ($this->dayNameScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_DayName($scannerTag); } } } public function scanForDayPortions($token) { foreach ($this->dayPortionScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_DayPortion($scannerTag); } } } public function scanForTimes($token, $options) { if (preg_match($this->timeRegex, $token->word)) { return new Horde_Date_Repeater_Time($token->word, $options); } } public function scanForUnits($token) { foreach ($this->unitScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { $class = 'Horde_Date_Repeater_' . Horde_String::ucfirst($scannerTag); return new $class($scannerTag); } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Scalar.php0000664000175000017500000000405712653700656023063 0ustar janjan &$token) { $postToken = isset($tokens[$i + 1]) ? $tokens[$i + 1]->word : null; if (!is_null($t = $this->scanForScalars($token, $postToken))) { $token->tag('scalar', $t); } if (!is_null($t = $this->scanForDays($token, $postToken))) { $token->tag('scalar_day', $t); } if (!is_null($t = $this->scanForMonths($token, $postToken))) { $token->tag('scalar_month', $t); } if (!is_null($t = $this->scanForYears($token, $postToken))) { $token->tag('scalar_year', $t); } } return $tokens; } public function scanForScalars($token, $postToken) { if (preg_match($this->scalarRegex, $token->word)) { if (!in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForDays($token, $postToken) { if (preg_match($this->dayRegex, $token->word)) { if ($token->word <= 31 && !in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForMonths($token, $postToken) { if (preg_match($this->monthRegex, $token->word)) { if ($token->word <= 12 && !in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForYears($token, $postToken) { if (preg_match($this->yearRegex, $token->word)) { if (!in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Separator.php0000664000175000017500000000356412653700656023620 0ustar janjan 'comma', ); public $slashOrDashScanner = array( '/^-$/' => 'dash', '/^\/$/' => 'slash', ); public $atScanner = array( '/^(at|@)$/' => 'at', ); public $inScanner = array( '/^in$/' => 'in', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForCommas($token)) { $token->tag('separator_comma', $t); } elseif ($t = $this->scanForSlashOrDash($token)) { $token->tag('separator_slash_or_dash', $t); } elseif ($t = $this->scanForAt($token)) { $token->tag('separator_at', $t); } elseif ($t = $this->scanForIn($token)) { $token->tag('separator_in', $t); } } return $tokens; } public function scanForCommas($token) { foreach ($this->commaScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForSlashOrDash($token) { foreach ($this->slashOrDashScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForAt($token) { foreach ($this->atScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForIn($token) { foreach ($this->inScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base/Timezone.php0000664000175000017500000000112112653700656023435 0ustar janjan 'tz', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForAll($token)) { $token->tag('timezone', $t); } } return $tokens; } public function scanForAll($token) { foreach ($this->scanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De/Grabber.php0000664000175000017500000000041712653700656022674 0ustar janjan 'last', '/diese\w?/' => 'this', '/nächste\w?/' => 'next', ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De/Ordinal.php0000664000175000017500000000027212653700656022717 0ustar janjan 'past', '/\bin\b/' => 'future', ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De/Repeater.php0000664000175000017500000000316712653700656023104 0ustar janjan 'january', '/^feb\.?(ruar)?$/' => 'february', '/^mär\.?(z)?$/' => 'march', '/^apr\.?(il)?$/' => 'april', '/^mai$/' => 'may', '/^jun\.?i?$/' => 'june', '/^jul\.?i?$/' => 'july', '/^aug\.?(ust)?$/' => 'august', '/^sep\.?(t\.?|tember)?$/' => 'september', '/^okt\.?(ober)?$/' => 'october', '/^nov\.?(ember)?$/' => 'november', '/^dez\.?(ember)?$/' => 'december', ); public $dayNameScanner = array( '/^mo(n(d?tag)?)?$/' => 'monday', '/^di(e(nst?tag)?)?$/' => 'tuesday', '/^mi(t(t?woch)?)?$/' => 'wednesday', '/^do(n(n?erstag)?)?$/' => 'thursday', '/^fr(e(itag)?)?$/' => 'friday', '/^sa(m(stag)?)?$/' => 'saturday', '/^so(n(ntag)?)?$/' => 'sunday', ); public $dayPortionScanner = array( '/^vormittags?$/' => 'morning', '/^(morgens?|früh)$/' => 'morning', '/^nachmittags?$/' => 'afternoon', '/^abends?$/' => 'evening', '/^nachts?$/' => 'night', '/^n8s?$/' => 'night', ); public $unitScanner = array( '/^jahre?$/' => 'year', //'/^seasons?$/' => 'season', ??? '/^monate?$/' => 'month', //'/^fortnights?$/' => 'fortnight', ?? '/^wochen?$/' => 'week', '/^wochenenden?$/' => 'weekend', '/^tage?$/' => 'day', '/^stunden?$/' => 'hour', '/^minuten?$/' => 'minute', '/^sekunden?$/' => 'second', ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De/Scalar.php0000664000175000017500000000014012653700656022526 0ustar janjan 'at', ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De/Timezone.php0000664000175000017500000000025012653700656023115 0ustar janjan 'tz', ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Grabber.php0000664000175000017500000000147412653700656022733 0ustar janjan 'last', '/n?est[ea]/' => 'this', '/(pr[oó]xim[oa]|seguinte)/' => 'next', '/last/' => 'last', '/this/' => 'this', '/next/' => 'next', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForAll($token)) { $token->tag('grabber', $t); } } return $tokens; } public function scanForAll($token) { foreach ($this->scanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Ordinal.php0000664000175000017500000000317012653700656022752 0ustar janjanscanForOrdinals($token))) { $token->tag('ordinal', $t); } if (!is_null($t = $this->scanForDays($token))) { $token->tag('ordinal_day', $t); } if (!is_null($t = $this->scanForMonths($token))) { $token->tag('ordinal_month', $t); } } return $tokens; } public function scanForOrdinals($token) { if (preg_match($this->ordinalRegex, $token->word, $matches)) { return (int)$matches[1]; } } public function scanForDays($token) { if (preg_match($this->ordinalDayRegex, $token->word, $matches)) { if ($matches[1] <= 31) { return (int)$matches[1]; } } } public function scanForMonths($token) { if (preg_match($this->ordinalMonthsRegex, $token->word, $matches)) { if ($matches[1] <= 12) { return (int)$matches[1]; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Pointer.php0000664000175000017500000000142612653700656023004 0ustar janjan 'past', '/^(depois(\s+de)?|ap[oó]s|dentro\s+de|daqui\s+a)$/' => 'future', '/\bpast\b/' => 'past', '/\bfuture\b/' => 'future', '/\bin\b/' => 'future', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForAll($token)) { $token->tag('pointer', $t); } } return $tokens; } public function scanForAll($token) { foreach ($this->scanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Repeater.php0000664000175000017500000001276712653700656023145 0ustar janjan 'january', '/^fev(ereiro)?$/' => 'february', '/^mar(co)?$/' => 'march', '/^abr(il)?$/' => 'april', '/^mai(o)?$/' => 'may', '/^jun(ho)?$/' => 'june', '/^jul(ho)?$/' => 'july', '/^ago(sto)?$/' => 'august', '/^set(embro)?$/' => 'september', '/^out(ubro)?$/' => 'october', '/^nov(embro)?$/' => 'november', '/^dez(embro)?$/' => 'december', ); /* public $monthNameScanner = array( '/^jan(\.|eiro)?$/' => 'january', '/^fev(\.|ereiro)?$/' => 'february', '/^mar(\.|(co))?$/' => 'march', '/^abr(\.|(il))?$/' => 'april', '/^mai(\.|o)?$/' => 'may', '/^jun(\.|ho)?$/' => 'june', '/^jul(\.|ho)?$/' => 'july', '/^ago(\.|sto)?$/' => 'august', '/^set(\.|embro)?$/' => 'september', '/^out(\.|ubro)?$/' => 'october', '/^nov(\.|embro)?$/' => 'november', '/^dez(\.|embro)?$/' => 'december', ); */ public $dayNameScanner = array( '/^seg$/' => 'monday', '/^ter$/' => 'tuesday', '/^qua$/' => 'wednesday', '/^qui$/' => 'thursday', '/^sex$/' => 'friday', '/^sab$/' => 'saturday', '/^dom$/' => 'sunday', '/^segunda$/' => 'monday', '/^terca$/' => 'tuesday', '/^quarta$/' => 'wednesday', '/^quinta$/' => 'thursday', '/^sexta$/' => 'friday', '/^sab(ado)?$/' => 'saturday', '/^dom(ingo)?$/' => 'sunday', ); /* '/^seg((unda)?(\s|\-)feira)?$/' => 'monday', '/^ter(([cç]a)?(\s|\-)feira)?$/' => 'tuesday', '/^qua((rta)?(\s|\-)feira)?$/' => 'wednesday', '/^qui((nta)?([ \-]feira)?)?$/' => 'thursday', '/^quinta-feira$/' => 'thursday', '/^sex((ta)?(\s|\-)feira)?$/' => 'friday', */ // scalar timeSignifiers? public $dayPortionScanner = array( '/^(\d*)\s?ams?$/' => 'am', '/^(\d*)\s?pms?$/' => 'pm', '/^(?:de|na|a|durante\s+a) (manh[aã]|madrugada)$/' => 'morning', '/^(?:de|na|a|durante\s+a) tarde$/' => 'afternoon', '/^((fim\s(d[ea]\s)tarde)|anoitecer)$/' => 'evening', '/^noite$/' => 'night', '/^ams?$/' => 'am', '/^pms?$/' => 'pm', '/^mornings?$/' => 'morning', '/^afternoons?$/' => 'afternoon', '/^evenings?$/' => 'evening', '/^(night|nite)s?$/' => 'night', //'/^horas?$/' => 'hour', // hour: add Repeater dayPortion (JPC) ); public $unitScanner = array( '/^anos?$/' => 'year', '/^(estacao|epoca)$/' => 'season', '/^mes$/' => 'month', '/^quinzena$/' => 'fortnight', '/^semanas?$/' => 'week', '/^(fds|fim( |( |\-)de( |\-))semana)?$/' => 'weekend', '/^dias?$/' => 'day', '/^horas?$/' => 'hour', '/^minutos?$/' => 'minute', '/^segundos?$/' => 'second', '/^years?$/' => 'year', '/^seasons?$/' => 'season', '/^months?$/' => 'month', '/^fortnights?$/' => 'fortnight', '/^weeks?$/' => 'week', '/^weekends?$/' => 'weekend', '/^days?$/' => 'day', '/^hours?$/' => 'hour', '/^minutes?$/' => 'minute', '/^seconds?$/' => 'second', ); public $timeRegex = '/^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/'; // 24h format //public $timeRegex = '/^([01]?[0-9]|2[0-3])(:?([0-5][0-9]))?([\.:]?([0-5][0-9]))?$/'; public function scan($tokens, $options) { foreach ($tokens as &$token) { if ($t = $this->scanForMonthNames($token)) { $token->tag('repeater_month_name', $t); } elseif ($t = $this->scanForDayNames($token)) { $token->tag('repeater_day_name', $t); } elseif ($t = $this->scanForDayPortions($token)) { $token->tag('repeater_day_portion', $t); } elseif ($t = $this->scanForTimes($token, $options)) { $token->tag('repeater_time', $t); } elseif ($t = $this->scanForUnits($token)) { $token->tag(Horde_String::lower(str_replace('Horde_Date_', '', get_class($t))), $t); } } return $tokens; } public function scanForMonthNames($token) { foreach ($this->monthNameScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_MonthName($scannerTag); } } } public function scanForDayNames($token) { foreach ($this->dayNameScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_DayName($scannerTag); } } } public function scanForDayPortions($token) { foreach ($this->dayPortionScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return new Horde_Date_Repeater_DayPortion($scannerTag); } } } public function scanForTimes($token, $options) { if (preg_match($this->timeRegex, $token->word)) { return new Horde_Date_Repeater_Time($token->word, $options); } } public function scanForUnits($token) { foreach ($this->unitScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { $class = 'Horde_Date_Repeater_' . Horde_String::ucfirst($scannerTag); return new $class($scannerTag); } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Scalar.php0000664000175000017500000000520712653700656022572 0ustar janjan &$token) { $postToken = isset($tokens[$i + 1]) ? $tokens[$i + 1]->word : null; if (!is_null($t = $this->scanForScalars($token, $postToken))) { $token->tag('scalar', $t); } if (!is_null($t = $this->scanForDays($token, $postToken))) { $token->tag('scalar_day', $t); } if (!is_null($t = $this->scanForMonths($token, $postToken))) { $token->tag('scalar_month', $t); } if (!is_null($t = $this->scanForYears($token, $postToken))) { $token->tag('scalar_year', $t); } } return $tokens; } public function scanForScalars($token, $postToken) { if (preg_match($this->scalarRegex, $token->word)) { if (!in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForDays($token, $postToken) { if (preg_match($this->dayRegex, $token->word)) { if ($token->word <= 31 && !in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForMonths($token, $postToken) { if (preg_match($this->monthRegex, $token->word)) { if ($token->word <= 12 && !in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } public function scanForYears($token, $postToken) { if (preg_match($this->yearRegex, $token->word)) { if (!in_array($postToken, $this->timeSignifiers)) { return $token->word; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Separator.php0000664000175000017500000000375312653700656023331 0ustar janjan 'comma', ); public $slashOrDashScanner = array( '/^-$/' => 'dash', '/^\/$/' => 'slash', ); public $atScanner = array( '/^(em|@|de)$/' => 'at', '/^(as|ao)$/' => 'at', '/^(at|@)$/' => 'at', ); public $inScanner = array( '/^no$/' => 'in', '/^in$/' => 'in', ); public function scan($tokens) { foreach ($tokens as &$token) { if ($t = $this->scanForCommas($token)) { $token->tag('separator_comma', $t); } elseif ($t = $this->scanForSlashOrDash($token)) { $token->tag('separator_slash_or_dash', $t); } elseif ($t = $this->scanForAt($token)) { $token->tag('separator_at', $t); } elseif ($t = $this->scanForIn($token)) { $token->tag('separator_in', $t); } } return $tokens; } public function scanForCommas($token) { foreach ($this->commaScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForSlashOrDash($token) { foreach ($this->slashOrDashScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForAt($token) { foreach ($this->atScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } public function scanForIn($token) { foreach ($this->inScanner as $scannerItem => $scannerTag) { if (preg_match($scannerItem, $token->word)) { return $scannerTag; } } } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt/Timezone.php0000664000175000017500000000043212653700656023152 0ustar janjan 'tz', // não pode ter modificadores, vai dar erro se usado ); } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Base.php0000664000175000017500000006334412653700656021662 0ustar janjanargs = $args; } /** # Parses a string containing a natural language date or time. If the parser # can find a date or time, either a Horde_Date or Horde_Date_Span will be returned # (depending on the value of :return). If no date or time can be found, # +nil+ will be returned. # # Options are: # # [:context] # :past or :future (defaults to :future) # # If your string represents a birthday, you can set :context to :past # and if an ambiguous string is given, it will assume it is in the # past. Specify :future or omit to set a future context. # # [:now] # Time (defaults to time()) # # By setting :now to a Horde_Date, all computations will be based off # of that time instead of time(). # # [:return] # 'result', 'span', or 'date' (defaults to 'date') # # By default, the parser will guess a single point in time for the # given date or time. If you'd rather have the entire time span returned, # set :return to 'span' and a Horde_Date_Span will be returned. # If you want the entire result, including tokens (for retrieving the text # that was or was not tagged, for example), set :return to 'result' # and you will get a result object. # # [:ambiguousTimeRange] # Integer or :none (defaults to 6 (6am-6pm)) # # If an Integer is given, ambiguous times (like 5:00) will be # assumed to be within the range of that time in the AM to that time # in the PM. For example, if you set it to 7, then the parser will # look for the time between 7am and 7pm. In the case of 5:00, it would # assume that means 5:00pm. If :none is given, no assumption # will be made, and the first matching instance of that time will # be used. */ public function parse($text, $specifiedOptions = array()) { // get options and set defaults if necessary $defaultOptions = array( 'context' => 'future', 'now' => new Horde_Date(time()), 'return' => 'date', 'ambiguousTimeRange' => 6, ); $options = array_merge($defaultOptions, $this->args, $specifiedOptions); // ensure the specified options are valid foreach (array_keys($specifiedOptions) as $key) { if (!isset($defaultOptions[$key])) { throw new InvalidArgumentException("$key is not a valid option key"); } } if (!in_array($options['context'], array('past', 'future', 'none'))) { throw new InvalidArgumentException("Invalid value " . $options['context'] . " for 'context' specified. Valid values are 'past', 'future', and 'none'"); } // store now for later =) $this->now = $options['now']; // put the text into a normal format to ease scanning $text = $this->preNormalize($text); // get base tokens for each word $tokens = $this->preTokenize($text); // scan the tokens with each token scanner foreach (array('Repeater') as $tokenizer) { $tokenizer = $this->componentFactory($tokenizer); $tokens = $tokenizer->scan($tokens, $options); } foreach (array('Grabber', 'Pointer', 'Scalar', 'Ordinal', 'Separator', 'Timezone') as $tokenizer) { $tokenizer = $this->componentFactory($tokenizer); $tokens = $tokenizer->scan($tokens); } // strip any non-tagged tokens $taggedTokens = array_values(array_filter($tokens, create_function('$t', 'return $t->tagged();'))); // Remove tokens we know we don't want - for example, if the first token // is a separator, drop it. $taggedTokens = $this->postTokenize($taggedTokens); // do the heavy lifting $span = $this->tokensToSpan($taggedTokens, $options); // generate the result and return it, the span, or a guessed time within the span $result = new Horde_Date_Parser_Result($span, $tokens); switch ($options['return']) { case 'result': return $result; case 'span': return $result->span; case 'date': return $result->guess(); } } public function componentFactory($component, $args = null) { $locale = isset($this->args['locale']) ? $this->args['locale'] : null; if ($locale && Horde_String::lower($locale) != 'base') { $locale = str_replace(' ', '_', Horde_String::ucwords(str_replace('_', ' ', Horde_String::lower($locale)))); $class = 'Horde_Date_Parser_Locale_' . $locale . '_' . $component; if (class_exists($class)) { return new $class($args); } $language = array_shift(explode('_', $locale)); if ($language != $locale) { $class = 'Horde_Date_Parser_Locale_' . $language . '_' . $component; if (class_exists($class)) { return new $class($args); } } } $class = 'Horde_Date_Parser_Locale_Base_' . $component; return new $class($args); } /** # Clean up the specified input text by stripping unwanted characters, # converting idioms to their canonical form, converting number words # to numbers (three => 3), and converting ordinal words to numeric # ordinals (third => 3rd) */ public function preNormalize($text) { $text = $this->numericizeNumbers($text); $text = preg_replace('/[\'"\.]/', '', $text); $text = preg_replace('/([\/\-\,\@])/', ' \1 ', $text); $text = preg_replace('/\btoday\b/i', 'this day', $text); $text = preg_replace('/\btomm?orr?ow\b/i', 'next day', $text); $text = preg_replace('/\byesterday\b/i', 'last day', $text); $text = preg_replace('/\bnoon\b/i', '12:00', $text); $text = preg_replace('/\bmidnight\b/i', '24:00', $text); $text = preg_replace('/\bbefore now\b/i', 'past', $text); $text = preg_replace('/\bnow\b/i', 'this second', $text); $text = preg_replace('/\b(ago|before)\b/i', 'past', $text); $text = preg_replace('/\bthis past\b/i', 'last', $text); $text = preg_replace('/\bthis last\b/i', 'last', $text); $text = preg_replace('/\b(?:in|during) the (morning)\b/i', '\1', $text); $text = preg_replace('/\b(?:in the|during the|at) (afternoon|evening|night)\b/i', '\1', $text); $text = preg_replace('/\btonight\b/i', 'this night', $text); $text = preg_replace('/((?=\w)\d+)([ap]m|oclock)\b/i', '$1 $2', $text); $text = preg_replace('/\b(hence|after|from)\b/i', 'future', $text); $text = $this->numericizeOrdinals($text); return $text; } /** * Convert number words to numbers (three => 3) */ public function numericizeNumbers($text) { return Horde_Support_Numerizer::numerize($text, $this->args); } /** * Convert ordinal words to numeric ordinals (third => 3rd) */ public function numericizeOrdinals($text) { return $text; } /** * Split the text on spaces and convert each word into a Token. * * @param string $text Text to tokenize * * @return array Array of Horde_Date_Parser_Tokens. */ public function preTokenize($text) { return array_map(create_function('$w', 'return new Horde_Date_Parser_Token($w);'), preg_split('/\s+/', $text)); } /** * Remove tokens that don't fit our definitions. * * @param array $tokens Array of tagged tokens. * * @return array Filtered tagged tokens. */ public function postTokenize($tokens) { if (!count($tokens)) { return $tokens; } // First rule: if the first token is a separator, remove it from the // list of tokens we consider in tokensToSpan(). $first = clone($tokens[0]); $first->untag('separator_at'); $first->untag('separator_comma'); $first->untag('separator_in'); $first->untag('separator_slash_or_dash'); if (!$first->tagged()) { array_shift($tokens); } // Second rule: if the last token is a separator, remove it from the // list of tokens we consider in tokensToSpan(). $last = clone($tokens[count($tokens) - 1]); $last->untag('separator_at'); $last->untag('separator_comma'); $last->untag('separator_in'); $last->untag('separator_slash_or_dash'); if (!$last->tagged()) { array_pop($tokens); } return $tokens; } public function initDefinitions() { if ($this->definitions) { return; } $this->definitions = array( 'time' => array( new Horde_Date_Parser_Handler(array(':repeater_time', ':repeater_day_portion?'), null), ), 'date' => array( new Horde_Date_Parser_Handler(array(':repeater_day_name', ':repeater_month_name', ':scalar_day', ':repeater_time', ':timezone', ':scalar_year'), 'handle_rdn_rmn_sd_t_tz_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year'), 'handle_rmn_sd_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year', ':separator_at?', 'time?'), 'handle_rmn_sd_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':separator_at?', 'time?'), 'handle_rmn_sd'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':ordinal_day', ':separator_at?', 'time?'), 'handle_rmn_od'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_year'), 'handle_rmn_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':repeater_month_name', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'), new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sm_sd_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_sm_sy'), new Horde_Date_Parser_Handler(array(':scalar_year', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_at?', 'time?'), 'handle_sy_sm_sd'), new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_year'), 'handle_sm_sy'), ), // tonight at 7pm 'anchor' => array( new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'), new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'), new Horde_Date_Parser_Handler(array(':repeater', ':grabber', ':repeater'), 'handle_r_g_r'), ), // 3 weeks from now, in 2 months 'arrow' => array( new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer'), 'handle_s_r_p'), new Horde_Date_Parser_Handler(array(':pointer', ':scalar', ':repeater'), 'handle_p_s_r'), new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer', 'anchor'), 'handle_s_r_p_a'), ), // 3rd week in march 'narrow' => array( new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':separator_in', ':repeater'), 'handle_o_r_s_r'), new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':grabber', ':repeater'), 'handle_o_r_g_r'), ), ); } public function tokensToSpan($tokens, $options) { $this->initDefinitions(); // maybe it's a specific date foreach ($this->definitions['date'] as $handler) { if ($handler->match($tokens, $this->definitions)) { $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator");'))); $this->debug($handler->handlerMethod, $goodTokens, $options); return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options); } } // I guess it's not a specific date, maybe it's just an anchor foreach ($this->definitions['anchor'] as $handler) { if ($handler->match($tokens, $this->definitions)) { $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator");'))); $this->debug($handler->handlerMethod, $goodTokens, $options); return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options); } } // not an anchor, perhaps it's an arrow foreach ($this->definitions['arrow'] as $handler) { if ($handler->match($tokens, $this->definitions)) { $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator_at") && !$o->getTag("separator_slash_or_dash") && !$o->getTag("separator_comma");'))); $this->debug($handler->handlerMethod, $goodTokens, $options); return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options); } } // not an arrow, let's hope it's a narrow foreach ($this->definitions['narrow'] as $handler) { if ($handler->match($tokens, $this->definitions)) { //good_tokens = tokens.select { |o| !o.get_tag Separator } $this->debug($handler->handlerMethod, $tokens, $options); return call_user_func(array($this, $handler->handlerMethod), $tokens, $options); } } return null; } public function dayOrTime($dayStart, $timeTokens, $options) { $outerSpan = new Horde_Date_Span($dayStart, $dayStart->add(array('day' => 1))); if (!empty($timeTokens)) { $this->now = $outerSpan->begin; return $this->getAnchor($this->dealiasAndDisambiguateTimes($timeTokens, $options), $options); } else { return $outerSpan; } } public function handle_m_d($month, $day, $timeTokens, $options) { $month->now = $this->now; $span = $month->this($options['context']); $dayStart = new Horde_Date($span->begin->year, $span->begin->month, $day); return $this->dayOrTime($dayStart, $timeTokens, $options); } public function handle_rmn_sd($tokens, $options) { return $this->handle_m_d($tokens[0]->getTag('repeater_month_name'), $tokens[1]->getTag('scalar_day'), array_slice($tokens, 2), $options); } public function handle_rmn_od($tokens, $options) { return $this->handle_m_d($tokens[0]->getTag('repeater_month_name'), $tokens[1]->getTag('ordinal_day'), array_slice($tokens, 2), $options); } public function handle_rmn_sy($tokens, $options) { $month = $tokens[0]->getTag('repeater_month_name')->index(); $year = $tokens[1]->getTag('scalar_year'); try { return new Horde_Date_Span(new Horde_Date($year, $month, 1), new Horde_Date($year, $month + 1, 1)); } catch (Exception $e) { return null; } } public function handle_rdn_rmn_sd_t_tz_sy($tokens, $options) { $month = $tokens[1]->getTag('repeater_month_name')->index(); $day = $tokens[2]->getTag('scalar_day'); $year = $tokens[5]->getTag('scalar_year'); try { $dayStart = new Horde_Date($year, $month, $day); return $this->dayOrTime($dayStart, array($tokens[3]), $options); } catch (Exception $e) { return null; } } public function handle_rmn_sd_sy($tokens, $options) { $month = $tokens[0]->getTag('repeater_month_name')->index(); $day = $tokens[1]->getTag('scalar_day'); $year = $tokens[2]->getTag('scalar_year'); $timeTokens = array_slice($tokens, 3); try { $dayStart = new Horde_Date($year, $month, $day); return $this->dayOrTime($dayStart, $timeTokens, $options); } catch (Exception $e) { return null; } } public function handle_sd_rmn_sy($tokens, $options) { $newTokens = array($tokens[1], $tokens[0], $tokens[2]); $timeTokens = array_slice($tokens, 3); return $this->handle_rmn_sd_sy(array_merge($newTokens, $timeTokens), $options); } public function handle_sm_sd_sy($tokens, $options) { $month = $tokens[0]->getTag('scalar_month'); $day = $tokens[1]->getTag('scalar_day'); $year = $tokens[2]->getTag('scalar_year'); $timeTokens = array_slice($tokens, 3); try { $dayStart = new Horde_Date($year, $month, $day); return $this->dayOrTime($dayStart, $timeTokens, $options); } catch (Exception $e) { return null; } } public function handle_sd_sm_sy($tokens, $options) { $newTokens = array($tokens[1], $tokens[0], $tokens[2]); $timeTokens = array_slice($tokens, 3); return $this->handle_sm_sd_sy(array_merge($newTokens, $timeTokens), $options); } public function handle_sy_sm_sd($tokens, $options) { $newTokens = array($tokens[1], $tokens[2], $tokens[0]); $timeTokens = array_slice($tokens, 3); return $this->handle_sm_sd_sy(array_merge($newTokens, $timeTokens), $options); } public function handle_sm_sy($tokens, $options) { $month = $tokens[0]->getTag('scalar_month'); $year = $tokens[1]->getTag('scalar_year'); try { return new Horde_Date_Span(new Horde_Date($year, $month, 1), new Horde_Date($year, $month + 1, 1)); } catch (Exception $e) { return null; } } /*########################################################################## # Anchors ##########################################################################*/ public function handle_r($tokens, $options) { $ddTokens = $this->dealiasAndDisambiguateTimes($tokens, $options); return $this->getAnchor($ddTokens, $options); } public function handle_r_g_r($tokens, $options) { $newTokens = array($tokens[1], $tokens[0], $tokens[2]); return $this->handle_r($newTokens, $options); } /*########################################################################## # Arrows ##########################################################################*/ public function handle_srp($tokens, $span, $options) { $distance = $tokens[0]->getTag('scalar'); $repeater = $tokens[1]->getTag('repeater'); $pointer = $tokens[2]->getTag('pointer'); return $repeater->offset($span, $distance, $pointer); } public function handle_s_r_p($tokens, $options) { $span = new Horde_Date_Span($this->now, $this->now->add(1)); return $this->handle_srp($tokens, $span, $options); } public function handle_p_s_r($tokens, $options) { $newTokens = array($tokens[1], $tokens[2], $tokens[0]); return $this->handle_s_r_p($newTokens, $options); } public function handle_s_r_p_a($tokens, $options) { $anchorSpan = $this->getAnchor(array_slice($tokens, 3), $options); return $this->handle_srp($tokens, $anchorSpan, $options); } /*########################################################################## # Narrows ##########################################################################*/ public function handle_orr($tokens, $outerSpan, $options) { $repeater = $tokens[1]->getTag('repeater'); $repeater->now = $outerSpan->begin->sub(1); $ordinal = $tokens[0]->getTag('ordinal'); $span = null; for ($i = 0; $i < $ordinal; $i++) { $span = $repeater->next('future'); if ($span->begin->after($outerSpan->end)) { $span = null; break; } } return $span; } public function handle_o_r_s_r($tokens, $options) { $outerSpan = $this->getAnchor(array($tokens[3]), $options); return $this->handle_orr(array($tokens[0], $tokens[1]), $outerSpan, $options); } public function handle_o_r_g_r($tokens, $options) { $outerSpan = $this->getAnchor(array($tokens[2], $tokens[3]), $options); return $this->handle_orr(array($tokens[0], $tokens[1]), $outerSpan, $options); } /*########################################################################## # Logging Methods ##########################################################################*/ public function debug($method, $args) { $args = func_get_args(); $method = array_shift($args); // echo "$method\n"; } /*########################################################################## # Support Methods ##########################################################################*/ public function getAnchor($tokens, $options) { $grabber = 'this'; $pointer = 'future'; $repeaters = $this->getRepeaters($tokens); for ($i = 0, $size = count($repeaters); $i < $size; $i++) { array_pop($tokens); } if (count($tokens) && $tokens[0]->getTag('grabber')) { $grabber = $tokens[0]->getTag('grabber'); array_pop($tokens); } $head = array_shift($repeaters); $head->now = $this->now; switch ($grabber) { case 'last': $outerSpan = $head->next('past'); break; case 'this': if (count($repeaters)) { $outerSpan = $head->this('none'); } else { $outerSpan = $head->this($options['context']); } break; case 'next': $outerSpan = $head->next('future'); break; default: throw new Horde_Date_Parser_Exception('Invalid grabber ' . $grabber); } return $this->findWithin($repeaters, $outerSpan, $pointer); } public function getRepeaters($tokens) { $repeaters = array(); foreach ($tokens as $token) { if ($t = $token->getTag('repeater')) { $repeaters[] = $t; } } // Return repeaters in order from widest (years) to smallest (seconds) usort($repeaters, create_function('$a, $b', 'return $b->width() > $a->width();')); return $repeaters; } /** * Recursively finds repeaters within other repeaters. Returns a Span * representing the innermost time span or null if no repeater union could * be found */ public function findWithin($tags, $span, $pointer) { if (empty($tags)) { return $span; } $head = array_shift($tags); $rest = $tags; $head->now = ($pointer == 'future') ? $span->begin : $span->end; $h = $head->this('none'); if ($span->includes($h->begin) || $span->includes($h->end)) { return $this->findWithin($rest, $h, $pointer); } else { return null; } } /** * handle aliases of am/pm * 5:00 in the morning -> 5:00 am * 7:00 in the evening -> 7:00 pm */ public function dealiasAndDisambiguateTimes($tokens, $options) { $dayPortionIndex = null; foreach ($tokens as $i => $t) { if ($t->getTag('repeater_day_portion')) { $dayPortionIndex = $i; break; } } $timeIndex = null; foreach ($tokens as $i => $t) { if ($t->getTag('repeater_time')) { $timeIndex = $i; break; } } if ($dayPortionIndex !== null && $timeIndex !== null) { $t1 = $tokens[$dayPortionIndex]; $t1tag = $t1->getTag('repeater_day_portion'); if ($t1tag->type == 'morning') { $t1->untag('repeater_day_portion'); $t1->tag('repeater_day_portion', new Horde_Date_Repeater_DayPortion('am')); } elseif (in_array($t1tag->type, array('afternoon', 'evening', 'night'))) { $t1->untag('repeater_day_portion'); $t1->tag('repeater_day_portion', new Horde_Date_Repeater_DayPortion('pm')); } } // handle ambiguous times if ambiguousTimeRange is specified if (!isset($options['ambiguousTimeRange']) || $options['ambiguousTimeRange'] != 'none') { $ttokens = array(); foreach ($tokens as $i => $t0) { $ttokens[] = $t0; $t1 = isset($tokens[$i + 1]) ? $tokens[$i + 1] : null; if ($t0->getTag('repeater_time') && $t0->getTag('repeater_time')->ambiguous && (!$t1 || !$t1->getTag('repeater_day_portion'))) { $distoken = new Horde_Date_Parser_Token('disambiguator'); $distoken->tag('repeater_day_portion', new Horde_Date_Repeater_DayPortion($options['ambiguousTimeRange'])); $ttokens[] = $distoken; } } $tokens = $ttokens; } return $tokens; } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/De.php0000664000175000017500000000471412653700656021334 0ustar janjan 3), and converting ordinal words to numeric * ordinals (third => 3rd) */ public function preNormalize($text) { $text = strtolower($text); $text = $this->numericizeNumbers($text); $text = preg_replace('/[\'"\.]/', '', $text); $text = preg_replace('/([\/\-\,\@])/', ' \1 ', $text); $text = preg_replace('/\bheute\b/', 'dieser tag', $text); $text = preg_replace('/\bmorgen\b/', 'nächster tag', $text); $text = preg_replace('/\bgestern\b/', 'letzter tag', $text); $text = preg_replace('/\bmittags?\b/', '12:00', $text); $text = preg_replace('/\bmitternachts?\b/', '24:00', $text); $text = preg_replace('/\bjetzt\b/', 'diese sekunde', $text); $text = preg_replace('/\b(vor|früher)\b/', 'past', $text); $text = preg_replace('/\b(?:in|during) the (morning)\b/', '\1', $text); $text = preg_replace('/\bam (morgen|nachmittag|abend)\b/', '\1', $text); $text = preg_replace('/\in der nacht\b/', 'nachts', $text); $text = $this->numericizeOrdinals($text); return $text; } /** * Remove tokens that don't fit our definitions and re-orders tokens when * necessary. * * @param array $tokens Array of tagged tokens. * * @return array Filtered tagged tokens. */ public function postTokenize($tokens) { $tokens = parent::postTokenize($tokens); // Catch ambiguous constructs like "heute morgen/morgen früh". foreach ($tokens as $num => $token) { if ($num >= 2 && ($repeater = $token->getTag('repeater')) && $repeater instanceof Horde_Date_Repeater_Day && ($grabber = $tokens[$num - 1]->getTag('grabber')) && $grabber == 'next') { $token = new Horde_Date_Parser_Token(''); $token->tag('repeater_day_portion', new Horde_Date_Repeater_DayPortion('morning')); array_splice( $tokens, $num - 1, 2, array($token)); return $tokens; } } return $tokens; } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Locale/Pt.php0000664000175000017500000004234712653700656021373 0ustar janjanargs = $args; } /** # Parses a string containing a natural language date or time. If the parser # can find a date or time, either a Horde_Date or Horde_Date_Span will be returned # (depending on the value of :return). If no date or time can be found, # +nil+ will be returned. # # Options are: # # [:context] # :past or :future (defaults to :future) # # If your string represents a birthday, you can set :context to :past # and if an ambiguous string is given, it will assume it is in the # past. Specify :future or omit to set a future context. # # [:now] # Time (defaults to time()) # # By setting :now to a Horde_Date, all computations will be based off # of that time instead of time(). # # [:return] # 'result', 'span', or 'date' (defaults to 'date') # # By default, the parser will guess a single point in time for the # given date or time. If you'd rather have the entire time span returned, # set :return to 'span' and a Horde_Date_Span will be returned. # If you want the entire result, including tokens (for retrieving the text # that was or was not tagged, for example), set :return to 'result' # and you will get a result object. # # [:ambiguousTimeRange] # Integer or :none (defaults to 6 (6am-6pm)) # # If an Integer is given, ambiguous times (like 5:00) will be # assumed to be within the range of that time in the AM to that time # in the PM. For example, if you set it to 7, then the parser will # look for the time between 7am and 7pm. In the case of 5:00, it would # assume that means 5:00pm. If :none is given, no assumption # will be made, and the first matching instance of that time will # be used. */ public function parse($text, $specifiedOptions = array()) { // get options and set defaults if necessary $defaultOptions = array( 'context' => 'future', 'now' => new Horde_Date(time()), 'return' => 'date', 'ambiguousTimeRange' => 6, ); $options = array_merge($defaultOptions, $this->args, $specifiedOptions); // ensure the specified options are valid foreach (array_keys($specifiedOptions) as $key) { if (!isset($defaultOptions[$key])) { throw new InvalidArgumentException("$key is not a valid option key"); } } if (!in_array($options['context'], array('past', 'future', 'none'))) { throw new InvalidArgumentException("Invalid value " . $options['context'] . " for 'context' specified. Valid values are 'past', 'future', and 'none'"); } // store now for later =) $this->now = $options['now']; $text = $this->normalize_special_characters($text); // put the text into a normal format to ease scanning $text = $this->preNormalize($text); // get base tokens for each word $tokens = $this->preTokenize($text); // scan the tokens with each token scanner foreach (array('Repeater') as $tokenizer) { $tokenizer = $this->componentFactory($tokenizer); $tokens = $tokenizer->scan($tokens, $options); } foreach (array('Grabber', 'Pointer', 'Scalar', 'Ordinal', 'Separator', 'Timezone') as $tokenizer) { $tokenizer = $this->componentFactory($tokenizer); $tokens = $tokenizer->scan($tokens); } // strip any non-tagged tokens $taggedTokens = array_values(array_filter($tokens, create_function('$t', 'return $t->tagged();'))); // Remove tokens we know we don't want - for example, if the first token // is a separator, drop it. $taggedTokens = $this->postTokenize($taggedTokens); // do the heavy lifting $span = $this->tokensToSpan($taggedTokens, $options); // generate the result and return it, the span, or a guessed time within the span $result = new Horde_Date_Parser_Result($span, $tokens); switch ($options['return']) { case 'result': return $result; case 'span': return $result->span; case 'date': return $result->guess(); } } /** Replaces special characters with non-special equivalents source: http://pt2.php.net/manual/en/function.chr.php#93291 */ public function normalize_special_characters( $str ) { # Quotes cleanup $str = ereg_replace( chr(ord("`")), "'", $str ); # ` $str = ereg_replace( chr(ord("´")), "'", $str ); # ´ $str = ereg_replace( chr(ord("„")), ",", $str ); # „ $str = ereg_replace( chr(ord("`")), "'", $str ); # ` $str = ereg_replace( chr(ord("´")), "'", $str ); # ´ $str = ereg_replace( chr(ord("“")), "\"", $str ); # “ $str = ereg_replace( chr(ord("”")), "\"", $str ); # ” $str = ereg_replace( chr(ord("´")), "'", $str ); # ´ $unwanted_array = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' ); $str = strtr( $str, $unwanted_array ); # Bullets, dashes, and trademarks $str = ereg_replace( chr(149), "•", $str ); # bullet • $str = ereg_replace( chr(150), "–", $str ); # en dash $str = ereg_replace( chr(151), "—", $str ); # em dash $str = ereg_replace( chr(153), "™", $str ); # trademark $str = ereg_replace( chr(169), "©", $str ); # copyright mark $str = ereg_replace( chr(174), "®", $str ); # registration mark return $str; } /** # Clean up the specified input text by stripping unwanted characters, # converting idioms to their canonical form, converting number words # to numbers (three => 3), and converting ordinal words to numeric # ordinals (third => 3rd) */ public function preNormalize($text) { // fix email parser $text = preg_replace('/\b([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})\b/', '', $text); $text = strtolower($text); $text = $this->numericizeNumbers($text); // fix url parser $text = preg_replace('/(?:(?:https?|ftp):\/\/)/', '', $text); // composed sentences $text = preg_replace('/\bsegunda[ \-]feira\b/', 'segunda', $text); $text = preg_replace('/\bterca[ \-]feira\b/', 'terca', $text); $text = preg_replace('/\bquarta[ \-]feira\b/', 'quarta', $text); $text = preg_replace('/\bquinta[ \-]feira\b/', 'quinta', $text); $text = preg_replace('/\bsexta[ \-]feira\b/', 'sexta', $text); $text = preg_replace('/[\'"\.]/', '', $text); $text = preg_replace('/([\/\-\,\@])/', ' $1 ', $text); $text = preg_replace('/\bhoje\b/', 'this day', $text); $text = preg_replace('/\bamanh[aã]\b/', 'next day', $text); $text = preg_replace('/\bontem\b/', 'last day', $text); $text = preg_replace('/\bfim de semana\b/', 'fds', $text); $text = preg_replace('/\bmeio\s+dia\b/', '12:00', $text); $text = preg_replace('/\bmeia\s+noite\b/', '24:00', $text); $text = preg_replace('/\b(antes|anterior)\b/', 'past', $text); $text = preg_replace('/\b(agora|j[aá])\b/', 'this second', $text); $text = preg_replace('/\b[uú]ltim[oa]\b/', 'last', $text); $text = preg_replace('/\b(?:de|na|durante\s+a|logo(?:\s[aà]|de))\s+(manh[aã]|madrugada)\b/', 'morning', $text); $text = preg_replace('/\b(?:de|[àa]|durante\s+a|logo(?:\s[aà]|de))\s+tarde\b/', 'afternoon', $text); $text = preg_replace('/\b((?:de|[àa]|durante\s+a|logo(?:\s[aà]))\s+noite|(?:ao)\s+anoitecer)\b/', 'this night', $text); $text = preg_replace_callback( '/\b([0-1]?[0-9]|2[0-3])(:|,|.)?([0-5][0-9])?\s?(horas?)\b/', create_function( '$matches', ' $minute = ($matches[3]!="")? str_pad($matches[3], 2 , "0", STR_PAD_LEFT): "00"; $hour = $matches[1]; return $hour.":".$minute." oclock"; ' ), $text); $text = preg_replace('/\b(horas?|h|hrs?)\b/', ' oclock', $text); $text = preg_replace('/\b(depois|ap[oó]s)\b/', 'future', $text); $text = preg_replace('/\bdia\b/', '', $text); // broke parser: redundant, ignore and read from number day // $text = $this->numericizeNumbers($text); return $text; } /** * Convert ordinal words to numeric ordinals (third => 3rd) */ public function numericizeOrdinals($text) { /* $text = preg_replace('/^d[eé]cim[oa]\s+primeir[oa]$/', '11º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+segund[oa]$/', '12º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+terceir[oa]$/', '13º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+quart[oa]$/', '14º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+quint[oa]$/', '15º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+sext[oa]$/', '16º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+s[eé]tim[oa]$/', '17º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+oit[aá]v[oa]$/', '18º', $text); $text = preg_replace('/^d[eé]cim[oa]\s+^non[oa]$/', '19º', $text); $text = preg_replace('/^primeir[oa]$/', '1º', $text); $text = preg_replace('/^segund[oa]$/', '2º', $text); $text = preg_replace('/^terceir[oa]$/', '3º', $text); $text = preg_replace('/^quart[oa]$/', '4º', $text); $text = preg_replace('/^quint[oa]$/', '5º', $text); $text = preg_replace('/^sext[oa]$/', '6º', $text); $text = preg_replace('/^s[eé]tim[oa]$/', '7º', $text); $text = preg_replace('/^oit[aá]v[oa]$/', '8º', $text); $text = preg_replace('/^non[oa]$/', '9º', $text); $text = preg_replace('/^d[eé]cim[oa]$/', '10º', $text); // and so one.... */ return $text; } public function initDefinitions() { if ($this->definitions) { return; } $this->definitions = array( 'time' => array( // new Horde_Date_Parser_Handler(array(':repeater_time', ':repeater_day_portion?'), null), new Horde_Date_Parser_Handler(array(':separator_at?', ':repeater_time', ':repeater_day_portion?'), null), new Horde_Date_Parser_Handler(array(':separator_at?', ':time', ':repeater_time'), null), // ás 10 horas /* new Horde_Date_Parser_Handler(array(':repeater_day_portion?', ':repeater_time' ), null), new Horde_Date_Parser_Handler(array(':separator_at?', ':repeater_time' ), null), new Horde_Date_Parser_Handler(array(':repeater_time', ':separator_at?', ':repeater_day_portion?'), null), */ ), 'date' => array( new Horde_Date_Parser_Handler(array(':repeater_day_name', ':repeater_month_name', ':scalar_day', ':repeater_time', ':timezone', ':scalar_year'), 'handle_rdn_rmn_sd_t_tz_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year'), 'handle_rmn_sd_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year', ':separator_at?', 'time?'), 'handle_rmn_sd_sy'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':separator_at?', 'time?'), 'handle_rmn_sd'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':ordinal_day', ':separator_at?', 'time?'), 'handle_rmn_od'), new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_year'), 'handle_rmn_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':repeater_month_name', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'), new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sm_sd_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_sm_sy'), new Horde_Date_Parser_Handler(array(':scalar_year', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_at?', 'time?'), 'handle_sy_sm_sd'), new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_year'), 'handle_sm_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'), /* new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', 'time?'), 'handle_sd_rmn'), new Horde_Date_Parser_Handler(array(':ordinal_day', ':separator_at?', ':repeater_month_name', ':separator_at?', 'time?'), 'handle_od_rmn'), new Horde_Date_Parser_Handler(array(':repeater_day_name', ':separator_at?', ':time?'), 'handle_rdn'), new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':scalar_month', ':separator_at?', ':scalar_year?', 'time?'), 'handle_sd_sm_sy'), new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'), */ new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_sm_sy'), new Horde_Date_Parser_Handler(array(':scalar_year', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_at?', 'time?'), 'handle_sy_sm_sd'), new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_year'), 'handle_sm_sy'), ), // tonight at 7pm 'anchor' => array( new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'), new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'), new Horde_Date_Parser_Handler(array(':repeater', ':grabber', ':repeater'), 'handle_r_g_r'), ), // 3 weeks from now, in 2 months 'arrow' => array( new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer'), 'handle_s_r_p'), new Horde_Date_Parser_Handler(array(':pointer', ':scalar', ':repeater'), 'handle_p_s_r'), new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer', 'anchor'), 'handle_s_r_p_a'), ), // 3rd week in march 'narrow' => array( new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':separator_in', ':repeater'), 'handle_o_r_s_r'), new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':grabber', ':repeater'), 'handle_o_r_g_r'), ), ); } public function handle_rdn($tokens, $options) { $day = $tokens[0]->getTag('repeater_day_name'); try { /* if ($day == date('j')) { $dayStart = new Horde_Date(time()); } else if ($day < date('j')) { $month = date('m'); $year = date('Y'); $dayStart = new Horde_Date($year, $month, $day); } else { if (date('m') == 12)) { $month = 1; $year = date('Y')+1; } else { $month = date('m'); $year = date('Y'); } $dayStart = new Horde_Date($year, $month, $day); } */ $dayStart = new Horde_Date(time()); return $this->dayOrTime($dayStart, array($tokens[0]), $options); } catch (Exception $e) { return null; } } // JPC public function handle_sd_rmn($tokens, $options) { return $this->handle_m_d($tokens[1]->getTag('repeater_month_name'), $tokens[0]->getTag('scalar_day'), array_slice($tokens, 2), $options); } public function handle_od_rmn($tokens, $options) { return $this->handle_m_d($tokens[1]->getTag('repeater_month_name'), $tokens[0]->getTag('ordinal_day'), array_slice($tokens, 2), $options); } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Exception.php0000664000175000017500000000007612653700656021540 0ustar janjanpattern = $pattern; $this->handlerMethod = $handlerMethod; } public function match($tokens, $definitions) { $tokenIndex = 0; foreach ($this->pattern as $name) { $optional = substr($name, -1) == '?'; if ($optional) { $name = rtrim($name, '?'); } $tag = substr($name, 0, 1) == ':'; if ($tag) { $name = substr($name, 1); //match = tokens[token_index] && !tokens[token_index].tags.select { |o| o.kind_of?(klass) }.empty? $match = isset($tokens[$tokenIndex]) && $tokens[$tokenIndex]->getTag($name); if (!$match && !$optional) { return false; } if ($match) { $tokenIndex++; continue; } if (!$match && $optional) { continue; } } else { if ($optional && $tokenIndex == count($tokens)) { return true; } if (!isset($definitions[$name])) { throw new Horde_Date_Parser_Exception("Invalid subset $name specified"); } $subHandlers = $definitions[$name]; foreach ($subHandlers as $subHandler) { if ($subHandler->match(array_slice($tokens, $tokenIndex), $definitions)) { return true; } } return false; } } if ($tokenIndex != count($tokens)) { return false; } return true; } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Result.php0000664000175000017500000000213112653700656021052 0ustar janjanspan = $span; $this->tokens = $tokens; } /** * Guess a specific time within the given span */ public function guess() { if (! $this->span instanceof Horde_Date_Span) { return null; } if ($this->span->width() > 1) { return $this->span->begin->add($this->span->width() / 2); } else { return $this->span->begin; } } public function taggedText() { $taggedTokens = array_values(array_filter($this->tokens, create_function('$t', 'return $t->tagged();'))); return implode(' ', array_map(create_function('$t', 'return $t->word;'), $taggedTokens)); } public function untaggedText() { $untaggedTokens = array_values(array_filter($this->tokens, create_function('$t', 'return ! $t->tagged();'))); return implode(' ', array_map(create_function('$t', 'return $t->word;'), $untaggedTokens)); } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser/Token.php0000664000175000017500000000250612653700656020662 0ustar janjanword = $word; $this->tags = array(); } /** * Tag this token with the specified tag */ public function tag($tagClass, $tag) { $this->tags[] = array($tagClass, $tag); } /** * Remove all tags of the given class */ public function untag($tagClass) { $this->tags = array_filter($this->tags, create_function('$t', 'return substr($t[0], 0, ' . strlen($tagClass) . ') != "' . $tagClass . '";')); } /** * Return true if this token has any tags */ public function tagged() { return count($this->tags) > 0; } /** * Return the Tag that matches the given class */ public function getTag($tagClass) { $matches = array_filter($this->tags, create_function('$t', 'return substr($t[0], 0, ' . strlen($tagClass) . ') == "' . $tagClass . '";')); $match = array_shift($matches); return $match[1]; } /** * Print this Token in a pretty way */ public function __toString() { $tags = array(); foreach ($this->tags as $t) { $tags[] = implode(': ', $t); } return '(' . implode(', ', $tags) . ') '; } } Horde_Date_Parser-2.0.5/lib/Horde/Date/Parser.php0000664000175000017500000000332612653700656017603 0ustar janjanparse($text, $args); } public static function factory($args = array()) { $locale = isset($args['locale']) ? $args['locale'] : null; if ($locale && Horde_String::lower($locale) != 'base') { $locale = str_replace(' ', '_', Horde_String::ucwords(str_replace('_', ' ', Horde_String::lower($locale)))); $class = 'Horde_Date_Parser_Locale_' . $locale; if (class_exists($class)) { return new $class($args); } $language = array_shift(explode('_', $locale)); if ($language != $locale) { $class = 'Horde_Date_Parser_Locale_' . $language; if (class_exists($class)) { return new $class($args); } } } return new Horde_Date_Parser_Locale_Base($args); } /** * Return a list of available locales */ public static function getLocales() { $dir = __DIR__ . '/Parser/Locale'; $locales = array(); foreach (new DirectoryIterator($dir) as $f) { if ($f->isFile()) { $locale = str_replace('.php', '', $f->getFilename()); $locale = preg_replace_callback('/([A-Z][a-z]*)([A-Z].*)?/', create_function('$m', 'if (!isset($m[2])) { return Horde_String::lower($m[1]); } else { return Horde_String::lower($m[1]) . "_" . Horde_String::upper($m[2]); }'), $locale); $locales[] = $locale; } } return $locales; } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/Locale/BaseTest.php0000664000175000017500000006736512653700656022742 0ustar janjannow = new Horde_Date('2006-08-16 14:00:00'); $this->parser = Horde_Date_Parser::factory(array('now' => $this->now)); } public function testTodayAt11() { $this->assertEquals('2006-08-16 11:00:00', (string)$this->parser->parse('today at 11')); } public function testTomorrow() { $this->assertEquals('2006-08-17 12:00:00', (string)$this->parser->parse('tomorrow')); } public function testMay27() { $this->assertEquals('2007-05-27 12:00:00', (string)$this->parser->parse('may 27')); } public function testThursday() { $this->assertEquals('2006-08-17 12:00:00', (string)$this->parser->parse('thursday')); } public function testNextMonth() { $this->assertEquals('2006-09-16 00:00:00', (string)$this->parser->parse('next month')); } public function testLastWeekTuesday() { $this->assertEquals('2006-08-08 12:00:00', (string)$this->parser->parse('last week tuesday')); } public function test3YearsAgo() { $this->assertEquals('2003-08-16 14:00:00', (string)$this->parser->parse('3 years ago')); $this->assertEquals('2003-08-16 14:00:00', (string)$this->parser->parse('three years ago')); } public function test6InTheMorning() { $this->assertEquals('2006-08-16 06:00:00', (string)$this->parser->parse('6 in the morning')); } public function testAfternoonYesterday() { $this->assertEquals('2006-08-15 15:00:00', (string)$this->parser->parse('afternoon yesterday')); } public function test3rdWednesdayInNovember() { $this->assertEquals('2006-11-15 12:00:00', (string)$this->parser->parse('3rd wednesday in november')); } public function test4thDayLastWeek() { $this->assertEquals('2006-08-09 12:00:00', (string)$this->parser->parse('4th day last week')); } public function testTwoMonthsAgoThisFriday() { $this->assertEquals('2006-06-18 12:00:00', (string)$this->parser->parse('two months ago this friday')); } public function testParseGuessDates_rm_sd() { $time = $this->parser->parse("may 27"); $this->assertEquals(new Horde_Date('2007-05-27 12:00:00'), $time); $time = $this->parser->parse("may 28", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-28 12:00:00'), $time); $time = $this->parser->parse("may 28 5pm", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-28 17:00:00'), $time); $time = $this->parser->parse("may 28 at 5pm", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-28 17:00:00'), $time); $time = $this->parser->parse("may 28 at 5:32.19pm", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-28 17:32:19'), $time); } public function testParseGuessDates_rm_od() { $time = $this->parser->parse("may 27th"); $this->assertEquals(new Horde_Date('2007-05-27 12:00:00'), $time); $time = $this->parser->parse("may 27th", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-27 12:00:00'), $time); $time = $this->parser->parse("may 27th 5:00 pm", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-27 17:00:00'), $time); $time = $this->parser->parse("may 27th at 5pm", array('context' => 'past')); $this->assertEquals(new Horde_Date('2006-05-27 17:00:00'), $time); $time = $this->parser->parse("may 27th at 5", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date('2007-05-27 05:00:00'), $time); } public function testParseGuessDates_rm_sy() { $time = $this->parser->parse("June 1979"); $this->assertEquals(new Horde_Date('1979-06-16 00:00:00'), $time); $time = $this->parser->parse("dec 79"); $this->assertEquals(new Horde_Date('1979-12-16 12:00:00'), $time); } public function testParseGuessDates_rm_sd_sy() { $time = $this->parser->parse("jan 3 2010"); $this->assertEquals(new Horde_Date('2010-01-03 12:00:00'), $time); $time = $this->parser->parse("jan 3 2010 midnight"); $this->assertEquals(new Horde_Date('2010-01-4 00:00:00'), $time); $time = $this->parser->parse("jan 3 2010 at midnight"); $this->assertEquals(new Horde_Date('2010-01-04 00:00:00'), $time); $time = $this->parser->parse("jan 3 2010 at 4", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date('2010-01-03 04:00:00'), $time); $time = $this->parser->parse("may 27 79"); $this->assertEquals(new Horde_Date('1979-05-27 12:00:00'), $time); $time = $this->parser->parse("may 27 79 4:30"); $this->assertEquals(new Horde_Date('1979-05-27 16:30:00'), $time); $time = $this->parser->parse("may 27 79 at 4:30", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date('1979-05-27 04:30:00'), $time); $time = $this->parser->parse("January 12, '00"); $this->markTestSkipped('not yet supported'); $this->assertEquals(new Horde_Date('2000-01-12 12:00:00'), $time); } public function testParseGuessDates_sd_rm_sy() { $time = $this->parser->parse("3 jan 2010"); $this->assertEquals(new Horde_Date('2010-01-03 12:00:00'), $time); $time = $this->parser->parse("3 jan 2010 4pm"); $this->assertEquals(new Horde_Date('2010-01-03 16:00:00'), $time); } public function testParseGuessDates_sm_sd_sy() { $time = $this->parser->parse("5/27/1979"); $this->assertEquals(new Horde_Date('1979-05-27 12:00:00'), $time); $time = $this->parser->parse("5/27/1979 4am"); $this->assertEquals(new Horde_Date('1979-05-27 04:00:00'), $time); } public function testParseGuessDates_sd_sm_sy() { $time = $this->parser->parse("27/5/1979"); $this->assertEquals(new Horde_Date('1979-05-27 12:00:00'), $time); $time = $this->parser->parse("27/5/1979 @ 0700"); $this->assertEquals(new Horde_Date('1979-05-27 07:00:00'), $time); } public function testParseGuessDates_sm_sy() { $time = $this->parser->parse("05/06"); $this->assertEquals(new Horde_Date('2006-05-16 12:00:00'), $time); $time = $this->parser->parse("12/06"); $this->assertEquals(new Horde_Date('2006-12-16 12:00:00'), $time); $time = $this->parser->parse("13/06"); $this->assertEquals(null, $time); } public function testParseGuessDates_sy_sm_sd() { $time = $this->parser->parse("2000-1-1"); $this->assertEquals(new Horde_Date('2000-01-01 12:00:00'), $time); $time = $this->parser->parse("2006-08-20"); $this->assertEquals(new Horde_Date('2006-08-20, 12:00:00'), $time); $time = $this->parser->parse("2006-08-20 7pm"); $this->assertEquals(new Horde_Date('2006-08-20, 19:00:00'), $time); $time = $this->parser->parse("2006-08-20 03:00"); $this->assertEquals(new Horde_Date('2006-08-20, 03:00:00'), $time); $time = $this->parser->parse("2006-08-20 03:30:30"); $this->assertEquals(new Horde_Date('2006-08-20 03:30:30'), $time); $time = $this->parser->parse("2006-08-20 15:30:30"); $this->assertEquals(new Horde_Date('2006-08-20 15:30:30'), $time); $time = $this->parser->parse("2006-08-20 15:30.30"); $this->assertEquals(new Horde_Date('2006-08-20 15:30:30'), $time); } public function testParseGuessDates_rdn_rm_rd_rt_rtz_ry() { $time = $this->parser->parse("Mon Apr 02 17:00:00 PDT 2007"); $this->assertEquals(new Horde_Date('2007-04-02 17:00:00'), $time); $now = new Horde_Date(time()); $time = $this->parser->parse((string)$now); $this->assertEquals((string)$now, (string)$time); } public function testParseGuessDates_rm_sd_rt() { $time = $this->parser->parse("jan 5 13:00"); $this->assertEquals(new Horde_Date('2007-01-05 13:00:00'), $time); } public function testParseGuessDatesOverflow() { $time = $this->parser->parse("may 40"); $this->assertEquals(new Horde_Date('2040-05-16 12:00:00'), $time); $time = $this->parser->parse("may 27 40"); $this->assertEquals(new Horde_Date('2040-05-27 12:00:00'), $time); $time = $this->parser->parse("1800-08-20"); $this->assertEquals(new Horde_Date('1800-08-20 12:00:00'), $time); } public function testParseGuess_r() { $time = $this->parser->parse("friday"); $this->assertEquals(new Horde_Date('2006-08-18 12:00:00'), $time); $time = $this->parser->parse("tue"); $this->assertEquals(new Horde_Date('2006-08-22 12:00:00'), $time); $time = $this->parser->parse("5"); $this->assertEquals(new Horde_Date('2006-08-16 17:00:00'), $time); $time = $this->parser->parse('5', array('now' => new Horde_Date('2006-08-16 03:00:00'), 'ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date('2006-08-16 05:00:00'), $time); $time = $this->parser->parse("13:00"); $this->assertEquals(new Horde_Date('2006-08-17 13:00:00'), $time); $time = $this->parser->parse("13:45"); $this->assertEquals(new Horde_Date('2006-08-17 13:45:00'), $time); $time = $this->parser->parse("november"); $this->assertEquals(new Horde_Date('2006-11-16 00:00:00'), $time); } public function testParseGuess_rr() { $time = $this->parser->parse("friday 13:00"); $this->assertEquals(new Horde_Date(2006, 8, 18, 13), $time); $time = $this->parser->parse("monday 4:00"); $this->assertEquals(new Horde_Date(2006, 8, 21, 16), $time); $time = $this->parser->parse("sat 4:00", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date(2006, 8, 19, 4), $time); $time = $this->parser->parse("sunday 4:20", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date(2006, 8, 20, 4, 20), $time); $time = $this->parser->parse("4 pm"); $this->assertEquals(new Horde_Date(2006, 8, 16, 16), $time); $time = $this->parser->parse("4 am", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date(2006, 8, 16, 4), $time); $time = $this->parser->parse("12 pm"); $this->assertEquals(new Horde_Date(2006, 8, 16, 12), $time); $time = $this->parser->parse("12:01 pm"); $this->assertEquals(new Horde_Date(2006, 8, 16, 12, 1), $time); $time = $this->parser->parse("12:01 am"); $this->assertEquals(new Horde_Date(2006, 8, 16, 0, 1), $time); $time = $this->parser->parse("12 am"); $this->assertEquals(new Horde_Date(2006, 8, 16), $time); $time = $this->parser->parse("4:00 in the morning"); $this->assertEquals(new Horde_Date(2006, 8, 16, 4), $time); $time = $this->parser->parse("november 4"); $this->assertEquals(new Horde_Date(2006, 11, 4, 12), $time); $time = $this->parser->parse("aug 24"); $this->assertEquals(new Horde_Date(2006, 8, 24, 12), $time); } public function testParseGuess_rrr() { $time = $this->parser->parse("friday 1 pm"); $this->assertEquals(new Horde_Date(2006, 8, 18, 13), $time); $time = $this->parser->parse("friday 11 at night"); $this->assertEquals(new Horde_Date(2006, 8, 18, 23), $time); $time = $this->parser->parse("friday 11 in the evening"); $this->assertEquals(new Horde_Date(2006, 8, 18, 23), $time); $time = $this->parser->parse("sunday 6am"); $this->assertEquals(new Horde_Date(2006, 8, 20, 6), $time); $time = $this->parser->parse("friday evening at 7"); $this->assertEquals(new Horde_Date(2006, 8, 18, 19), $time); } public function testParseGuess_g_r_Year() { $this->markTestIncomplete('Fails specifically on ci.horde.org and only when using test-framework. I am clueless..'); $time = $this->parser->parse("this year"); $this->assertEquals(new Horde_Date(2006, 10, 24, 12, 30), $time); $span = $this->parser->parse("this year", array('context' => 'past', 'return' => 'span')); $this->assertEquals(new Horde_Date_Span('2006-01-01 00:00:00', '2006-08-16 00:00:00'), $span); } public function testParseGuess_g_r_Month() { $time = $this->parser->parse("this month"); $this->assertEquals(new Horde_Date(2006, 8, 24, 12), $time); $time = $this->parser->parse("this month", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 8, 12), $time); $time = $this->parser->parse("next month", array('now' => new Horde_Date(2006, 11, 15))); $this->assertEquals(new Horde_Date(2006, 12, 16, 12), $time); } public function testParseGuess_g_r_MonthName() { $time = $this->parser->parse("last november"); $this->assertEquals(new Horde_Date(2005, 11, 16), $time); } public function testParseGuess_g_r_Fortnight() { $time = $this->parser->parse("this fortnight"); $this->assertEquals(new Horde_Date(2006, 8, 21, 19, 30), $time); $time = $this->parser->parse("this fortnight", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 14, 19), $time); } public function testParseGuess_g_r_Week() { $time = $this->parser->parse("this week"); $this->assertEquals(new Horde_Date(2006, 8, 18, 7, 30), $time); $time = $this->parser->parse("this week", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 14, 19), $time); } public function testParseGuess_g_r_Weekend() { $time = $this->parser->parse("this weekend"); $this->assertEquals(new Horde_Date(2006, 8, 20), $time); $time = $this->parser->parse("this weekend", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 13), $time); $time = $this->parser->parse("last weekend"); $this->assertEquals(new Horde_Date(2006, 8, 13), $time); } public function testParseGuess_g_r_Day() { $time = $this->parser->parse("this day"); $this->assertEquals(new Horde_Date(2006, 8, 16, 19, 30), $time); $time = $this->parser->parse("this day", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 16, 7), $time); $time = $this->parser->parse("today"); $this->assertEquals(new Horde_Date(2006, 8, 16, 19, 30), $time); $time = $this->parser->parse("yesterday"); $this->assertEquals(new Horde_Date(2006, 8, 15, 12), $time); $time = $this->parser->parse("tomorrow"); $this->assertEquals(new Horde_Date(2006, 8, 17, 12), $time); } public function testParseGuess_g_r_DayName() { $time = $this->parser->parse("this tuesday"); $this->assertEquals(new Horde_Date(2006, 8, 22, 12), $time); $time = $this->parser->parse("next tuesday"); $this->assertEquals(new Horde_Date(2006, 8, 22, 12), $time); $time = $this->parser->parse("last tuesday"); $this->assertEquals(new Horde_Date(2006, 8, 15, 12), $time); $time = $this->parser->parse("this wed"); $this->assertEquals(new Horde_Date(2006, 8, 23, 12), $time); $time = $this->parser->parse("next wed"); $this->assertEquals(new Horde_Date(2006, 8, 23, 12), $time); $time = $this->parser->parse("last wed"); $this->assertEquals(new Horde_Date(2006, 8, 9, 12), $time); } public function testParseGuess_g_r_DayPortion() { $time = $this->parser->parse("this morning"); $this->assertEquals(new Horde_Date(2006, 8, 16, 9), $time); $time = $this->parser->parse("tonight"); $this->assertEquals(new Horde_Date(2006, 8, 16, 22), $time); } public function testParseGuess_g_r_Minute() { $time = $this->parser->parse("next minute"); $this->assertEquals(new Horde_Date(2006, 8, 16, 14, 1, 30), $time); } public function testParseGuess_g_r_Second() { $time = $this->parser->parse("this second"); $this->assertEquals(new Horde_Date(2006, 8, 16, 14), $time); $time = $this->parser->parse("this second", array('context' => 'past')); $this->assertEquals(new Horde_Date(2006, 8, 16, 14), $time); $time = $this->parser->parse("next second"); $this->assertEquals(new Horde_Date(2006, 8, 16, 14, 0, 1), $time); $time = $this->parser->parse("last second"); $this->assertEquals(new Horde_Date(2006, 8, 16, 13, 59, 59), $time); } public function testParseGuess_g_rr() { $time = $this->parser->parse("yesterday at 4:00"); $this->assertEquals(new Horde_Date(2006, 8, 15, 16), $time); $time = $this->parser->parse("today at 9:00"); $this->assertEquals(new Horde_Date(2006, 8, 16, 9), $time); $time = $this->parser->parse("today at 2100"); $this->assertEquals(new Horde_Date(2006, 8, 16, 21), $time); $time = $this->parser->parse("this day at 0900"); $this->assertEquals(new Horde_Date(2006, 8, 16, 9), $time); $time = $this->parser->parse("tomorrow at 0900"); $this->assertEquals(new Horde_Date(2006, 8, 17, 9), $time); $time = $this->parser->parse("yesterday at 4:00", array('ambiguousTimeRange' => 'none')); $this->assertEquals(new Horde_Date(2006, 8, 15, 4), $time); $time = $this->parser->parse("last friday at 4:00"); $this->assertEquals(new Horde_Date(2006, 8, 11, 16), $time); $time = $this->parser->parse("next wed 4:00"); $this->assertEquals(new Horde_Date(2006, 8, 23, 16), $time); $time = $this->parser->parse("yesterday afternoon"); $this->assertEquals(new Horde_Date(2006, 8, 15, 15), $time); $time = $this->parser->parse("last week tuesday"); $this->assertEquals(new Horde_Date(2006, 8, 8, 12), $time); $time = $this->parser->parse("tonight at 7"); $this->assertEquals(new Horde_Date(2006, 8, 16, 19), $time); $time = $this->parser->parse("tonight 7"); $this->assertEquals(new Horde_Date(2006, 8, 16, 19), $time); $time = $this->parser->parse("7 tonight"); $this->assertEquals(new Horde_Date(2006, 8, 16, 19), $time); } public function testParseGuess_g_rrr() { $time = $this->parser->parse("today at 6:00pm"); $this->assertEquals(new Horde_Date(2006, 8, 16, 18), $time); $time = $this->parser->parse("today at 6:00am"); $this->assertEquals(new Horde_Date(2006, 8, 16, 6), $time); $time = $this->parser->parse("this day 1800"); $this->assertEquals(new Horde_Date(2006, 8, 16, 18), $time); $time = $this->parser->parse("yesterday at 4:00pm"); $this->assertEquals(new Horde_Date(2006, 8, 15, 16), $time); $time = $this->parser->parse("tomorrow evening at 7"); $this->assertEquals(new Horde_Date(2006, 8, 17, 19), $time); $time = $this->parser->parse("tomorrow morning at 5:30"); $this->assertEquals(new Horde_Date(2006, 8, 17, 5, 30), $time); $time = $this->parser->parse("next monday at 12:01 am"); $this->assertEquals(new Horde_Date(2006, 8, 21, 00, 1), $time); $time = $this->parser->parse("next monday at 12:01 pm"); $this->assertEquals(new Horde_Date(2006, 8, 21, 12, 1), $time); } public function testParseGuess_r_g_r() { $time = $this->parser->parse("afternoon yesterday"); $this->assertEquals(new Horde_Date(2006, 8, 15, 15), $time); $time = $this->parser->parse("tuesday last week"); $this->assertEquals(new Horde_Date(2006, 8, 8, 12), $time); } public function testParseGuess_s_r_p_Past() { $time = $this->parser->parse("3 years ago"); $this->assertEquals(new Horde_Date(2003, 8, 16, 14), $time); $time = $this->parser->parse("1 month ago"); $this->assertEquals(new Horde_Date(2006, 7, 16, 14), $time); $time = $this->parser->parse("1 fortnight ago"); $this->assertEquals(new Horde_Date(2006, 8, 2, 14), $time); $time = $this->parser->parse("2 fortnights ago"); $this->assertEquals(new Horde_Date(2006, 7, 19, 14), $time); $time = $this->parser->parse("3 weeks ago"); $this->assertEquals(new Horde_Date(2006, 7, 26, 14), $time); $time = $this->parser->parse("2 weekends ago"); $this->assertEquals(new Horde_Date(2006, 8, 5), $time); $time = $this->parser->parse("3 days ago"); $this->assertEquals(new Horde_Date(2006, 8, 13, 14), $time); $time = $this->parser->parse("5 mornings ago"); $this->assertEquals(new Horde_Date(2006, 8, 12, 9), $time); $time = $this->parser->parse("7 hours ago"); $this->assertEquals(new Horde_Date(2006, 8, 16, 7), $time); $time = $this->parser->parse("3 minutes ago"); $this->assertEquals(new Horde_Date(2006, 8, 16, 13, 57), $time); $time = $this->parser->parse("20 seconds before now"); $this->assertEquals(new Horde_Date(2006, 8, 16, 13, 59, 40), $time); $this->markTestSkipped('not yet supported'); $time = $this->parser->parse("1 monday ago"); $this->assertEquals(new Horde_Date(2006, 8, 14, 12), $time); } public function testParseGuess_s_r_p_Future() { $time = $this->parser->parse("3 years from now"); $this->assertEquals(new Horde_Date(2009, 8, 16, 14, 0, 0), $time); $time = $this->parser->parse("6 months hence"); $this->assertEquals(new Horde_Date(2007, 2, 16, 14), $time); $time = $this->parser->parse("3 fortnights hence"); $this->assertEquals(new Horde_Date(2006, 9, 27, 14), $time); $time = $this->parser->parse("1 week from now"); $this->assertEquals(new Horde_Date(2006, 8, 23, 14, 0, 0), $time); $time = $this->parser->parse("1 weekend from now"); $this->assertEquals(new Horde_Date(2006, 8, 19), $time); $time = $this->parser->parse("2 weekends from now"); $this->assertEquals(new Horde_Date(2006, 8, 26), $time); $time = $this->parser->parse("1 day hence"); $this->assertEquals(new Horde_Date(2006, 8, 17, 14), $time); $time = $this->parser->parse("5 mornings hence"); $this->assertEquals(new Horde_Date(2006, 8, 21, 9), $time); $time = $this->parser->parse("1 hour from now"); $this->assertEquals(new Horde_Date(2006, 8, 16, 15), $time); $time = $this->parser->parse("20 minutes hence"); $this->assertEquals(new Horde_Date(2006, 8, 16, 14, 20), $time); $time = $this->parser->parse("20 seconds from now"); $this->assertEquals(new Horde_Date(2006, 8, 16, 14, 0, 20), $time); $time = $this->parser->parse("2 months ago", array('now' => new Horde_Date('2007-03-07 23:30'))); $this->assertEquals(new Horde_Date(2007, 1, 7, 23, 30), $time); } public function testParseGuess_p_s_r() { $time = $this->parser->parse("in 3 hours"); $this->assertEquals(new Horde_Date(2006, 8, 16, 17), $time); } public function testParseGuess_s_r_p_a_Past() { $time = $this->parser->parse("3 years ago tomorrow"); $this->assertEquals(new Horde_Date(2003, 8, 17, 12), $time); $time = $this->parser->parse("3 years ago this friday"); $this->assertEquals(new Horde_Date(2003, 8, 18, 12), $time); $time = $this->parser->parse("3 months ago saturday at 5:00 pm"); $this->assertEquals(new Horde_Date(2006, 5, 19, 17), $time); $time = $this->parser->parse("2 days from this second"); $this->assertEquals(new Horde_Date(2006, 8, 18, 14), $time); $time = $this->parser->parse("7 hours before tomorrow at midnight"); $this->assertEquals(new Horde_Date(2006, 8, 17, 17), $time); } public function testParseGuess_s_r_p_a_Future() { $this->markTestIncomplete(); } public function testParseGuess_o_r_s_r() { $time = $this->parser->parse("3rd wednesday in november"); $this->assertEquals(new Horde_Date(2006, 11, 15, 12), $time); $time = $this->parser->parse("10th wednesday in november"); $this->assertEquals(null, $time); $time = $this->parser->parse("3rd wednesday in 2007"); $this->markTestSkipped('not yet supported'); $this->assertEquals(new Horde_Date(2007, 1, 20, 12), $time); } public function testParseGuess_o_r_g_r() { $span = $this->parser->parse("3rd month next year", array('return' => 'span')); $this->assertEquals(new Horde_Date_Span('2007-03-01 00:00:00', '2007-04-01 00:00:00'), $span); $time = $this->parser->parse("3rd thursday this september"); $this->assertEquals(new Horde_Date(2006, 9, 21, 12), $time); $time = $this->parser->parse("4th day last week"); $this->assertEquals(new Horde_Date(2006, 8, 9, 12), $time); } public function testParseGuessNonsense() { $time = $this->parser->parse("some stupid nonsense"); $this->assertEquals(null, $time); } public function testParseSpan() { $span = $this->parser->parse('friday', array('return' => 'span')); $this->assertEquals(new Horde_Date(2006, 8, 18), $span->begin); $this->assertEquals(new Horde_Date(2006, 8, 19), $span->end); $span = $this->parser->parse('november', array('return' => 'span')); $this->assertEquals(new Horde_Date(2006, 11, 1), $span->begin); $this->assertEquals(new Horde_Date(2006, 12, 1), $span->end); $span = $this->parser->parse('weekend', array('return' => 'span')); $this->assertEquals(new Horde_Date(2006, 8, 19), $span->begin); $this->assertEquals(new Horde_Date(2006, 8, 21), $span->end); } public function testParseWords() { $this->assertEquals($this->parser->parse("33 days from now"), $this->parser->parse("thirty-three days from now")); $this->assertEquals($this->parser->parse("2867532 seconds from now"), $this->parser->parse("two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now")); $this->assertEquals($this->parser->parse("may 10th"), $this->parser->parse("may tenth")); } public function testParseOnlyCompletePointers() { $this->assertEquals($this->now, $this->parser->parse("eat pasty buns today at 2pm")); $this->assertEquals($this->now, $this->parser->parse("futuristically speaking today at 2pm")); $this->assertEquals($this->now, $this->parser->parse("meeting today at 2pm")); } public function testParseTextWithSlashes() { $time = $this->parser->parse("tomorrow 5pm empty dishwasher / load dishwasher"); $this->assertEquals(new Horde_Date(2006, 8, 17, 17), $time); } public function testArgumentValidation() { try { $this->parser->parse('may 27', array('foo' => 'bar')); $this->fail("Should throw InvalidArgumentException"); } catch (InvalidArgumentException $e) { } catch (Exception $e) { $this->fail("Should throw InvalidArgumentException, threw " . get_class($e)); } try { $this->parser->parse('may 27', array('context' => 'bar')); $this->fail("Should throw InvalidArgumentException"); } catch (InvalidArgumentException $e) { } catch (Exception $e) { $this->fail("Should throw InvalidArgumentException, threw " . get_class($e)); } } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/Locale/DeTest.php0000664000175000017500000000211212653700656022373 0ustar janjannow = new Horde_Date('2006-08-16 14:00:00'); $this->parser = Horde_Date_Parser::factory(array('locale' => 'de', 'now' => $this->now)); } public function testTodayAt11() { $this->assertEquals('2006-08-16 11:00:00', (string)$this->parser->parse('heute um 11')); } public function testTomorrow() { $this->assertEquals('2006-08-17 09:00:00', (string)$this->parser->parse('morgen früh', array(), false)); } public function testMorning() { $this->assertEquals('2006-08-16 09:00:00', (string)$this->parser->parse('heute morgen', array(), false)); } public function testNight() { $this->assertEquals('2006-08-16 22:00:00', (string)$this->parser->parse('heute nacht', array(), false)); } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/AllTests.php0000664000175000017500000000013212653700656021537 0ustar janjanrun(); Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/bootstrap.php0000664000175000017500000000014312653700656022023 0ustar janjannow = new Horde_Date('2006-08-16 14:00:00'); } public function testHandlerClass1() { /* $handler = Chronic::Handler.new([:repeater], :handler) tokens = [Chronic::Token.new('friday')] tokens[0].tag(Chronic::RepeaterDayName.new(:friday)) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('afternoon') tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon)) assert !handler.match(tokens, Chronic.definitions) */ } public function testHandlerClass2() { /* handler = Chronic::Handler.new([:repeater, :repeater?], :handler) tokens = [Chronic::Token.new('friday')] tokens[0].tag(Chronic::RepeaterDayName.new(:friday)) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('afternoon') tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon)) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('afternoon') tokens[2].tag(Chronic::RepeaterDayPortion.new(:afternoon)) assert !handler.match(tokens, Chronic.definitions) */ } public function testHandlerClass3() { /* handler = Chronic::Handler.new([:repeater, 'time?'], :handler) tokens = [Chronic::Token.new('friday')] tokens[0].tag(Chronic::RepeaterDayName.new(:friday)) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('afternoon') tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon)) assert !handler.match(tokens, Chronic.definitions) */ } public function testHandlerClass4() { /* handler = Chronic::Handler.new([:repeater_month_name, :scalar_day, 'time?'], :handler) tokens = [Chronic::Token.new('may')] tokens[0].tag(Chronic::RepeaterMonthName.new(:may)) assert !handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('27') tokens[1].tag(Chronic::ScalarDay.new(27)) assert handler.match(tokens, Chronic.definitions) */ } public function testHandlerClass5() { /* handler = Chronic::Handler.new([:repeater, 'time?'], :handler) tokens = [Chronic::Token.new('friday')] tokens[0].tag(Chronic::RepeaterDayName.new(:friday)) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('5:00') tokens[1].tag(Chronic::RepeaterTime.new('5:00')) assert handler.match(tokens, Chronic.definitions) tokens << Chronic::Token.new('pm') tokens[2].tag(Chronic::RepeaterDayPortion.new(:pm)) assert handler.match(tokens, Chronic.definitions) */ } public function testHandlerClass6() { /* handler = Chronic::Handler.new([:scalar, :repeater, :pointer], :handler) tokens = [Chronic::Token.new('3'), Chronic::Token.new('years'), Chronic::Token.new('past')] tokens[0].tag(Chronic::Scalar.new(3)) tokens[1].tag(Chronic::RepeaterYear.new(:year)) tokens[2].tag(Chronic::Pointer.new(:past)) assert handler.match(tokens, Chronic.definitions) */ } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/ParserTest.php0000664000175000017500000000611612653700656022110 0ustar janjannow = new Horde_Date('2006-08-16 14:00:00'); } public function testPostNormalizeAmPmAliases() { // affect wanted patterns $tokens = array(new Horde_Date_Parser_Token('5:00'), new Horde_Date_Parser_Token('morning')); $tokens[0]->tag('repeater_time', new Horde_Date_Repeater_Time('5:00')); $tokens[1]->tag('repeater_day_portion', new Horde_Date_Repeater_DayPortion('morning')); $this->assertEquals('morning', $tokens[1]->tags[0][1]->type); $parser = Horde_Date_Parser::factory(); $tokens = $parser->dealiasAndDisambiguateTimes($tokens, array()); $this->assertEquals('am', $tokens[1]->tags[0][1]->type); $this->assertEquals(2, count($tokens)); // don't affect unwanted patterns $tokens = array(new Horde_Date_Parser_Token('friday'), new Horde_Date_Parser_Token('morning')); $tokens[0]->tag('repeater_day_name', 'friday'); $tokens[1]->tag('repeater_day_portion', 'morning'); $this->assertEquals('morning', $tokens[1]->tags[0][1]); $parser = Horde_Date_Parser::factory(); $tokens = $parser->dealiasAndDisambiguateTimes($tokens, array()); $this->assertEquals('morning', $tokens[1]->tags[0][1]); $this->assertEquals(2, count($tokens)); } public function testPreNormalizeAmPm() { $parser = Horde_Date_Parser::factory(); $text = $parser->preNormalize('5am'); $this->assertEquals('5 am', $text); $text = $parser->preNormalize('5:00am'); $this->assertEquals('5:00 am', $text); $text = $parser->preNormalize('5 am'); $this->assertEquals('5 am', $text); $text = $parser->preNormalize('exam'); $this->assertEquals('exam', $text); } public function testPreNormalizeCase() { $parser = Horde_Date_Parser::factory(); $this->assertEquals('this day', $parser->preNormalize('Today')); $this->assertEquals('this day', $parser->preNormalize('today')); $this->assertEquals('this day', $parser->preNormalize('toDay')); $this->assertEquals('next day', $parser->preNormalize('Tommorow')); $this->assertEquals('next day', $parser->preNormalize('tommorow')); $this->assertEquals('next day', $parser->preNormalize('TOMMOROW')); $this->assertEquals('next day', $parser->preNormalize('tomorow')); $this->assertEquals('last day', $parser->preNormalize('Yesterday')); $this->assertEquals('last day', $parser->preNormalize('yesterday')); $this->assertEquals('12:00', $parser->preNormalize('Noon')); $this->assertEquals('12:00', $parser->preNormalize('noon')); $this->assertEquals('24:00', $parser->preNormalize('Midnight')); $this->assertEquals('24:00', $parser->preNormalize('midnight')); } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/phpunit.xml0000664000175000017500000000005612653700656021511 0ustar janjan Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/ResultTest.php0000664000175000017500000000167012653700656022132 0ustar janjanspan = new Horde_Date_Span(new Horde_Date('2006-08-16 00:00:00'), new Horde_Date('2006-08-17 00:00:00')); $this->assertEquals(new Horde_Date('2006-08-16 12:00:00'), $result->guess()); $result->span = new Horde_Date_Span(new Horde_Date('2006-08-16 00:00:00'), new Horde_Date('2006-08-17 00:00:01')); $this->assertEquals(new Horde_Date('2006-08-16 12:00:00'), $result->guess()); $result->span = new Horde_Date_Span(new Horde_Date('2006-11-01 00:00:00'), new Horde_Date('2006-12-01 00:00:00')); $this->assertEquals(new Horde_Date('2006-11-16 00:00:00'), $result->guess()); } } Horde_Date_Parser-2.0.5/test/Horde/Date/Parser/TokenTest.php0000664000175000017500000000412112653700656021726 0ustar janjanassertEquals('foo', $token->word); $this->assertEquals(0, count($token->tags)); $this->assertFalse($token->tagged()); $token->tag('foo', 'mytag'); $this->assertEquals(1, count($token->tags)); $this->assertTrue($token->tagged()); $this->assertInternalType('string', $token->getTag('foo')); $token->tag('bar', 5); $this->assertEquals(2, count($token->tags)); $this->assertInternalType('int', $token->getTag('bar')); $token->untag('foo'); $this->assertEquals(1, count($token->tags)); $this->assertInternalType('int', $token->getTag('bar')); } public function testScanForDayNames() { $parser = Horde_Date_Parser::factory(); $tokenizer = $parser->componentFactory('Repeater'); $token = new Horde_Date_Parser_Token('saturday'); $repeater = $tokenizer->scanForDayNames($token); $this->assertInstanceOf('Horde_Date_Repeater_DayName', $repeater); $this->assertEquals('saturday', $repeater->type); $token = new Horde_Date_Parser_Token('sunday'); $repeater = $tokenizer->scanForDayNames($token); $this->assertInstanceOf('Horde_Date_Repeater_DayName', $repeater); $this->assertEquals('sunday', $repeater->type); } public function testScanForTz() { $parser = Horde_Date_Parser::factory(); $tokenizer = $parser->componentFactory('Timezone'); $token = new Horde_Date_Parser_Token('test'); $results = $tokenizer->scan(array($token)); $this->assertEmpty($results[0]->getTag('timezone')); $token = new Horde_Date_Parser_Token('EST'); $results = $tokenizer->scan(array($token)); $this->assertEquals('tz', $results[0]->getTag('timezone')); } }