Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WCM] Added information about the new date handling in the comparison constraints and Range #4143

Closed
wants to merge 1 commit into from

Conversation

webmozart
Copy link
Contributor

Q A
Doc fix? no
New docs? yes (symfony/symfony#11673)
Applies to 2.6+
Fixed tickets -

<property name="deliveryDate">
<constraint name="GreaterThan">today</constraint>
</property>
</class>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have fully working XML examples:

<!-- src/Acme/OrderBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

    <class name="Acme\OrderBundle\Entity\Order">
        <property name="deliveryDate">
            <constraint name="GreaterThan">today</constraint>
        </property>
    </class>
</constraint-mapping>

This also applies to the other XML code blocks below.

@weaverryan weaverryan changed the title Added information about the new date handling in the comparison constraints and Range [WCM] Added information about the new date handling in the comparison constraints and Range Aug 20, 2014
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Aug 24, 2014
…ts and Range (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added date support to comparison constraints and Range

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #3640, #7766, #9164, #9390, #8300
| License       | MIT
| Doc PR        | symfony/symfony-docs#4143

This commit adds frequently requested functionality to compare dates. Since the `DateTime` constructor is very flexible, you can do many fancy things now such as:

```php
/**
 * Only accept requests that start in at least an hour.
 * @Assert\GreaterThanOrEqual("+1 hours")
 */
private $date;

/**
 * Same as before.
 * @Assert\Range(min = "+1 hours")
 */
private $date;

/**
 * Only accept dates in the current year.
 * @Assert\Range(min = "first day of January", max = "first day of January next year")
 */
private $date;

/**
 * Timezones are supported.
 * @Assert\Range(min = "first day of January UTC", max = "first day of January next year UTC")
 */
private $date;
```

Commits
-------

60a5863 [Validator] Added date support to comparison constraints and Range
symfony-splitter pushed a commit to symfony/validator that referenced this pull request Aug 24, 2014
…ts and Range (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added date support to comparison constraints and Range

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #3640, #7766, #9164, #9390, #8300
| License       | MIT
| Doc PR        | symfony/symfony-docs#4143

This commit adds frequently requested functionality to compare dates. Since the `DateTime` constructor is very flexible, you can do many fancy things now such as:

```php
/**
 * Only accept requests that start in at least an hour.
 * @Assert\GreaterThanOrEqual("+1 hours")
 */
private $date;

/**
 * Same as before.
 * @Assert\Range(min = "+1 hours")
 */
private $date;

/**
 * Only accept dates in the current year.
 * @Assert\Range(min = "first day of January", max = "first day of January next year")
 */
private $date;

/**
 * Timezones are supported.
 * @Assert\Range(min = "first day of January UTC", max = "first day of January next year UTC")
 */
private $date;
```

Commits
-------

60a5863 [Validator] Added date support to comparison constraints and Range
}

Be aware that PHP will use the server's configured timezone to interpret these
dates. If you want to fix the timezone, append it to the date string:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a minor question regarding this phrase:

If you want to fix the timezone ...

Does fix always imply that something is broken? In that case, we could change it for something like this:

If you want to use a custom timezone ...
If you want to set a different timezone ...
If you want to configure the timezone explicitly ...

What I mean is that the server timezone isn't broken, it's just different from what we may need.

@wouterj
Copy link
Member

wouterj commented Nov 5, 2014

@webmozart could you please update this PR to fix the comments?

@@ -8,7 +8,7 @@ Validates that a value is equal to another value, defined in the options. To
force that a value is *not* equal, see :doc:`/reference/constraints/NotEqualTo`.

.. caution::

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it useful to explain how to compare Date instances here too?

@xabbuh
Copy link
Member

xabbuh commented Mar 8, 2015

@webmozart Will you be able to complete this or will you prefer if somebody takes this over?

fago pushed a commit to fago/Validator that referenced this pull request Apr 18, 2015
…ts and Range (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Added date support to comparison constraints and Range

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #3640, #7766, #9164, #9390, #8300
| License       | MIT
| Doc PR        | symfony/symfony-docs#4143

This commit adds frequently requested functionality to compare dates. Since the `DateTime` constructor is very flexible, you can do many fancy things now such as:

```php
/**
 * Only accept requests that start in at least an hour.
 * @Assert\GreaterThanOrEqual("+1 hours")
 */
private $date;

/**
 * Same as before.
 * @Assert\Range(min = "+1 hours")
 */
private $date;

/**
 * Only accept dates in the current year.
 * @Assert\Range(min = "first day of January", max = "first day of January next year")
 */
private $date;

/**
 * Timezones are supported.
 * @Assert\Range(min = "first day of January UTC", max = "first day of January next year UTC")
 */
private $date;
```

Commits
-------

60a5863 [Validator] Added date support to comparison constraints and Range
@wouterj
Copy link
Member

wouterj commented May 15, 2015

Hi @webmozart. Do you have some time soon to finish this PR? If you don't, please say so as we can then assign it to someone else during the doc sprint day on May 23rd.

Thanks!

@javiereguiluz
Copy link
Member

This PR has been finished in #5384

@xabbuh
Copy link
Member

xabbuh commented Jun 11, 2015

closing in favor of #5384

@xabbuh xabbuh closed this Jun 11, 2015
weaverryan added a commit that referenced this pull request Jun 28, 2015
…mparison constraints and Range (webmozart, javiereguiluz)

This PR was submitted for the 2.7 branch but it was merged into the 2.6 branch instead (closes #5384).

Discussion
----------

Added information about the new date handling in the comparison constraints and Range

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#11673)
| Applies to    | 2.6+
| Fixed tickets | -

This PR finishes #4143

Commits
-------

b6c1a93 Added the "payload" option back
7ef2e6a Show annotations first
e3efbbf Reordered the code blocks to show Annotations, YAML, XML and PHP
39f46e1 Fixed the issues reported by @xabbuh
7003445 Finished the documentation of the new data comparison validators
1fa69fe Added information about the new date handling in the comparison constraints and Range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants