0

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.

8
  • What format is your backend expecting? Have you tried using the ISO 8601 date format? startDate.format() will return the date in iso format Commented Aug 20, 2015 at 13:56
  • @AnishPatel It's expecting 'Y-m-d H:i:s' Commented Aug 20, 2015 at 14:09
  • You are using YYYY-MM-DD HH:mm which is missing the seconds. Also the first exception indicate that a timezone was expected, use Z in the format string. Try YYYY-MM-DD HH:mm:ssZ, alternatively try my first suggestion of using the ISO format, I can't see a standard date time library not recognizing an ISO date. Commented Aug 20, 2015 at 14:17
  • @AnishPatel Tried to do that but to no avail. This is what print_r returns after attempting to submit a form, if it helps at all: [startdate:protected] => DateTime Object ( [date] => 2015-08-20 16:00:00 [timezone_type] => 1 [timezone] => +01:00 ) [enddate:protected] => DateTime Object ( [date] => 2015-08-20 16:45:00 [timezone_type] => 1 [timezone] => +01:00 ) Commented Aug 20, 2015 at 15:05
  • Have you tried new Date(startDate.format("YYYY-MM-DD HH:mm")).toISOString()? Commented Aug 20, 2015 at 15:08

1 Answer 1

1

Figured out where the issue was. Basically there was a validate behaviour on the Propel schema:

<behavior name="validate"> ... <parameter name="rule3" value="{column: enddate, validator: GreaterThan, options: {value: StartDate, message: End date is required}}" /> </behavior> 

It was passing string "StartDate" instead of an actual value. Removing it fixed the issue.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.