Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validate Year
  • When using a validation rule like so:

    [code]$v->add_rule('year', 'Year', 'required|valid_date[Y]');[/code]

    You can post, say 2006, but the validated year will output one year less, 2005.

    Internally, _validate_valid_date is using the built in function date_parse_from_format. When passed just a year (Y) the returned array ($parsed) only contains the year - no month or day, meaning that the call to date($format, mktime($parsed array elements)) returns one year less.

    I hope that makes sense..?

    To "fix" this, i amended the function to make sure that $parsed[month] and $parsed[day] were set:

    [code]
    date($format, mktime($parsed['hour'], $parsed['minute'], $parsed['second'], (!empty($parsed['month'])?$parsed['month']:1), (!empty($parsed['day'])?$parsed['day']:1), $parsed['year']));
    [/code]

  • Can you send a pull request for this fix?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion