Commit graph

15 commits

Author SHA1 Message Date
Henrique Moody 92a8ab13cf
Fix coding standards
These are the changes after running the last version of PHP-CS-Fixer.
2018-02-04 01:00:30 +01:00
Henrique Moody fb2ebaf5d6
Apply contribution guidelines to "DateTime" rule
This commit also makes some changes in how the `DateTime` rule behaves,
by not accepting `DateTimeInterface` as valid when a format is given.

Also:
- Create `DateTimeHelper` to eliminate some code duplication;
- Create integration tests for `DateTime` rule;
- Rename "format" placeholder to "sample" in the message;
- Update documentation of "DateTime" rule.
2018-01-30 20:17:10 +01:00
Henrique Moody 0db1cd6e1b
Create "Date" rule 2018-01-29 09:39:57 +01:00
Henrique Moody 0338e18e83
Rename rule "Date" to "DateTime"
Also change rules to use `DateTimeInterface` and `DateTimeImmutable`
when possible.
2017-05-01 13:16:59 +02:00
Henrique Moody 4d72af312f
Update PHP-CS-Fixer settings 2016-10-30 10:39:23 +01:00
Emmerson d0a98ae5d3
Date rule accepting scalar and DateTimeInterface 2016-09-19 10:13:01 +02:00
Henrique Moody 294368294f Merge branch '0.9' into 1.0 2016-03-31 14:39:15 -03:00
Henrique Moody eecc696792 Fix wrong date parsing on Date rule
The `DateTime::createFromFormat()` tries to guess the date too much and
sometimes wrong parsing may happen:

```php
echo DateTime::createFromFormat('Ym', '202309')->format('Ym');
```

The output of the above code is "202310", not "202309".

Using `date_parse_from_format()` we get a more precise parsing.
2016-03-31 14:18:22 -03:00
Henrique Moody 9c49dd3bcf Use short array syntax 2015-10-17 22:56:32 -03:00
Henrique Moody a3c945aa51 Add license information and copyright in all files 2015-06-08 12:09:25 -03:00
Henrique Moody b8c76e3054 Fix some coding standards 2015-06-08 11:51:45 -03:00
qrazi b4bb681fd3 The creation of a DateTime-object from the input-string keeps the given
timezone information. However, in the comparison the DateTime-object is
first output to a timestamp, which is then converted to a string with the
date()-function. But because a timestamp does not include timezone
information, date() will assume the system's timezone. So if the system
timezone set in the PHP settings is UTC, a string with another timezone,
e.g. 2015-04-24T21:11:00+02:00, will fail to be validated. The result from
the date()-function in this example is 2015-04-24T19:11:00+00:00, which is
a different string then the input.
The DateTime-class has also an option to create a string from a format,
DateTime->format(). So it is possible to skip the use of the
date()-function with the added benefit that using format() does have
access to the timezone information and thus produces the expected
2015-04-24T21:11:00+02:00 to compare with the given input.

This commit changes the Rule to accommodate this and expands the tests. If
these added tests are run before applying the fix to the Date-rule, the
tests will fail.
2015-04-24 23:03:45 +02:00
Henrique Moody da193b75e0 Use PSR-2 standard
Most changes was made by php-cs-fixer.
Also removes unused `RecursiveTreeIterator` class.
2015-01-08 00:44:12 -02:00
Eduardo Reveles 00940cfee9 Translate date formats to something DateTime::createFromFormat can understand. 2014-10-01 01:09:27 -05:00
Graham Campbell ae056920b4 PSR-4 autoloading 2014-07-12 20:20:43 +01:00
Renamed from library/Respect/Validation/Rules/Date.php (Browse further)