I have a form which returns a date/time value. This is the code for the relevant bit (it's javascript code in Knockout JS, which the site utilises as well as Propel which uses Symfony for validation, among other things, and MomentJS for date formatting):
self.startDate = ko.computed(function() {
var startDate = moment(self.timesheetDate() + " " + self.startTime());
return startDate.format("YYYY-MM-DD HH:mm");
}, self);
console.log(self.startDate()); // returns '2015-08-20 14:00'
Unfortunately, when submitting the form, it returns this error:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (startdate) at position 0 (s): The timezone could not be found in the database' in C:\wamp\www\iq\vendor\symfony\validator\Constraints\AbstractComparisonValidator.php on line 53
I tried passing the value as a JavaScript Date object instead:
self.startDate = ko.computed(function() {
var startDate = moment(self.timesheetDate() + " " + self.startTime());
return new Date(startDate.format("YYYY-MM-DD HH:mm"));
}, self);
console.log(self.startDate()); // returns 'Thu Aug 20 2015 14:00:00 GMT+0100 (GMT Daylight Time)'
But get this error:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Thu Aug 20 2015 14:00:00 GMT+0100 (GMT Daylight Time)) at position 39 (D): Double timezone specification' in C:\wamp\www\iq\vendor\propel\propel\src\Propel\Runtime\Util\PropelDateTime.php on line 96
All packages are up-to-date.
Does anyone have an idea how this could be fixed?
Thank you in advance.
Edit: I tried to hardcode the date using:
$timesheet->setStartDate(date_format(date_create('2015-08-08 11:10:00'), 'Y-m-d H:i:s'));
but it didn't help. Here is what print_r returns after the form fails to create:
DateTime Object ( [date] => 2015-08-08 11:10:00 [timezone_type] => 3 [timezone] => Europe/London )
which seems correct? So I am really at a loss as to why I am getting the error.