I am unable to set the year below 1899 for a post. If i set year below 1899 it is set to the current year automatically.
I have purchased the Timeline theme and asked in their support forum. They replied:
This sounds like a limitation created by your hosting provider. Nothing in the theme is preventing the date you assign â as you can see, the demo has posts using dates in the 1400s. Try contacting your hosting provider and see if they have any insight on how to address that.
This is not really an answer, just an attempt to find the specific context for this problem. Please install the following plugin on your site, try to set the three dates and add your result to the second
<pre>
in the table below.Gist of the Plugin can be checked out here.
0999
, click Update. Is it saved or changed to the current date?1899
,2020
and2039
.Question and expectations
While the literal form of this question is practical in context (year 1899) it is a little vague in theoretical sense. How old is old? How far into the past we might want to go? What about the future?
Since WordPress had started out as blogging engine, in that contextual sense it evolved to handle following span of time:
As WordPress usage evolved into non-blogging applications such projects (commonly history and art as I have seen from reports) started to hit assorted issues with dates outside of this span.
For the purpose of my research I had formulated following questions:
Platform limitations
Since WordPress is PHP application and uses MySQL for data storage it’s subject to their limitations.
MySQL
WordPress stores post dates in
post_date
column ofDATETIME
type in MySQL.According to documentation this type supports years 1000 to 9999:
However it also says that earlier values might work, no mention of later values:
While empirically I have observed values out of range working, this is anecdotal and falls out of our reliability condition.
PHP
In PHP programming Unix timestamp representation of date is widely used. According to documentation for our purposes (PHP 5.2+ and generic 32 bit environment) it supports years (in full) 1902 to 2037:
Other than that newer
Date/Time
based handling is 64 bit and has range roughly -292 billion to 292 billion years, which probably exceeds humanity needs at this time.WordPress limitations
WordPress introduces and inherits some additional limitation in its code base.
Data flow
From basic user workflow point of view there are two processed related to date:
Note that these are technically completely different and independent processes. As further explained their ranges do not overlap and saving correct date does not equal ability to correctly read it in WordPress environment.
Explicit limits
_wp_translate_postdata()
processes year (submitted as distinct number from form) and:wp_checkdate()
, which calls PHP nativecheckdate()
, which imposes limit of 1 to 32767Implicit limits
strtotime()
PHP function is used multiple times and is subject to above mentioned Unix timestamp, at the lowest level inmysql2date()
that affects all reads of dates from database, 1902 to 2037 range inheritedget_gmt_from_date()
, which expects year to be([0-9]{1,4})
, limiting it 1 to 9999, strong possibility of similar processing in other functions that will require more thorough code audit to be enumeratedPossibility of workarounds
wp_checkdate()
haswp_checkdate
filter, which allows to override this validation checkdate_i18n()
which hasdate_i18n
filter, theoretically allows to completely intercept and re-process output of dates to interface however challenging if function is passed already out of range (false
) timestamp inputConclusions
For the practical purposes and portability of data WordPress post date range seems to be equal to that of 32 bit Unix timestamp and consist of years 1902 to 2037 inclusively.
For any post date operation out of this range environment must be audited (64 bit range of Unix timestamps, de-facto functioning MySQL or alternate database storage for the values). For farther ranges (below 1000, above 9999) considerable amounts of custom code are likely to be required.
For any implementation of arbitrary dates it makes sense to:
Date/Time
-based code and/or WordPress functions audited not to be affected by Unix timestamp limitsCode test bed
The following code and hand picked set of years have been used for research above and testing of conclusions: