Skip to content

Conversation

franzliedke
Copy link
Contributor

This allows for validating a PHP date format.

Rules would look like this:

'start_time' => 'date_format:"H:i"',

Note the quotes wrapping the value so that the colon does not count as parameter separator.


Everything documented and properly unit-tested.

@Anahkiasen
Copy link
Contributor

+1 for this, I've been needing it a lot lately

@JoostK
Copy link
Contributor

JoostK commented Sep 7, 2012

Genius, thanks!

@daylerees
Copy link
Contributor

I see some extra commits in this pull :/

@Anahkiasen
Copy link
Contributor

Well yeah but it's all related to what he added, no ?

@franzliedke
Copy link
Contributor Author

I think I messed up merging a little bit - because I have two remotes, origin (my repo) and upstream (the official one).

@daylerees Would you mind simply squashing my commits into one? That would keep the history clean. I don't care that much about my original commits being there (although you could of course have me as author in the squashed one). ;)

@franzliedke
Copy link
Contributor Author

Ah, sheesh.

When merging this, please make sure the language key is added to all then-existent language files!

@Jakobud
Copy link
Contributor

Jakobud commented Oct 3, 2012

+1 to this pull request. This should be in there.

@drakakisgeo
Copy link
Contributor

+10!

@hasokeric
Copy link

looks good

@daylerees daylerees merged commit de53feb into laravel:develop Jan 6, 2013
@daylerees
Copy link
Contributor

Manual merging this. Thanks Franz!

@franzliedke
Copy link
Contributor Author

@daylerees Some ugly files are still in the repo tree.

@daylerees
Copy link
Contributor

Hmm, not sure where they came from, but they have been removed now :) cheers mate.

@mjbrunme
Copy link

PHP's date_parse_from_format is either broken or is intentionally far too lenient to use for validating formatting on simple date parts. You can not, for example, validate a 2 digit year vs 4 digit year, or a month with or without leading zeroes.

For example, if you set up the rule:

'year' => 'date_format:Y',
'month' => 'date_format:m'

and pass the following:

['year'=>'16', 'month'=>'3']

It will not report any errors. You would expect it to fail on both, since the year should be 4 digits and the month should include a leading 0.

@mansouralex
Copy link

Hello @franzliedke ,@mjbrunme I'm facing a related issue with the Y format:

The rule as: date_format:d-m-Y and it's accepting such date: "21-12-0020"

Any thoughts how we can restrict this and end up with valid year ?

@ncpope
Copy link

ncpope commented Apr 25, 2017 via email

@satodu
Copy link

satodu commented Apr 25, 2017

I used CARBON. http://carbon.nesbot.com/docs/

It's made easier, you can install using the caomposer and call the object in your controller.

@mansouralex
Copy link

mansouralex commented Apr 25, 2017

@satodu I'm already aware and using CARBON. But how do you suggest we can employ it in this case?

@troccoli
Copy link

troccoli commented Apr 25, 2017 via email

@satodu
Copy link

satodu commented Apr 25, 2017

@mansouralex

$dt = Carbon::createFromDate(0020, 10, 6);
if ($dt->year < 2012) {
echo 'Man! it's too old';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.