Skip to content

[Validator] added before and after options to Date constraints #8300

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

Closed
wants to merge 1 commit into from

Conversation

bamarni
Copy link
Contributor

@bamarni bamarni commented Jun 17, 2013

Q A
Bug fix? [no]
New feature? [yes]
BC breaks? [no]
Deprecations? [no]
Tests pass? [yes]
License MIT
Doc PR [todo]

I've added an after and before options to Date and DateTime constraints. It uses the strtotime function so it's user friendly, values like "now", "+1 week" can be used.

I think it can be very useful, some examples :

  • an appointment can't be scheduled before 10 days
  • a user must be more than 16 years old (checking the birthday)
  • a date must be in the future

What do you think?

@fabpot
Copy link
Member

fabpot commented Nov 28, 2013

#8034

@bamarni
Copy link
Contributor Author

bamarni commented Nov 28, 2013

you're saying it should be added in a new constraint? see also #7766 #9164

@fabpot
Copy link
Member

fabpot commented Dec 29, 2013

closing as a duplicate for #7766

@fabpot fabpot closed this Dec 29, 2013
nicolas-grekas added a commit 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
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.

2 participants