Given that I have 3 integers representing a date
dd
mm
and yyyy
I tried to set a date property in an object. So far I can’t figure out the "right" or easy way to do it.
I know that the final representation of the date is going to be yyyy-mm-dd, so it seems like it should be easy to do.
After looking at the xPDOObject::set method:
if (in_array($v, $this->_currentDates) || $v === '0000-00-00') {
$this->_fields[$k]= $v;
$set= true;
} elseif ($v) {
$ts= strtotime($v);
if ($ts !== -1 && $ts !== false) {
$this->_fields[$k]= $this->strftime('%Y-%m-%d', $ts);
$set= true;
}
}
.. if the date you pass in is not in the _currentDates list, or is not ’0000-00-00’, then it gets passed to php’s strtotime() function.
Just looking at the documentation for that function, it seems to have some fairly irregular behavior across different versions of php. Also, the date I was trying to set in my own little test, 1968-12-10, since it’s pre-Unix epoch, doesn’t work in Windows or "some versions of Linux".
I wonder if it would be preferable to open up the first test to allow the user to pass in a string already in the right format. I don’t know if this would incur too much overhead.. something like
if (in_array($v, $this->_currentDates) || preg_match("/^\d{4}\-\d{2}\-\d{2}$/", $v)) {
Of course, I might be overlooking some obvious approach to setting the date using the code as it is.
Tock tick...
nP