Field_timestamp currently offers very rudimentary validation, checking only to ensure that form values are provided. In fact, the current implementation will happily accept alphanumeric characters entered for the year, causing php warnings. With warnings turned off, the dates are quietly set to 1/1/1970, which could confuse non-technical users. (For these reasons, I've set this as a bug as opposed to a feature. I can see either way.)

This patch offers more robust validation, ensuring that:

* year provides is either 2 digit or 4 digit
* month, hour and minute are accepable values
* day is a valid entry for given month & year, with account being taken for leap years

Note that restrictions on acceptable values for year are platform specific. The patch implements a set of restrictions based on systems commonly in use today, namely:
- 2 digit dates must be < 38 (maps to 2000+)
- 2 digit date must be > 69 (maps to 1970+)
- 4 digit dates must be between 1901 and 2038

64-bit systems may allow a broader range. If you are running a 64-bit system and need a broader range, try editing the validation rules.

For additional info see: http://www.php.net/manual/en/function.mktime.php

Note that this patch is dependent on the patch supplied in issue 59733.

CommentFileSizeAuthor
robust_date_validation.patch3.78 KBsamc

Comments

samc’s picture

Correction, this patch is dependent on the patch supplied in issue 54215.

samc’s picture

Also wanted to mention that this patch renames a function to improve clarity... flexinode_validate_date() is now called flexinode_get_timestamp() which seems much more appropriate.