dqwh1119 2015-08-20 13:47
浏览 66
已采纳

无法解析时间字符串...:双时区规范

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.

  • 写回答

1条回答 默认 最新

  • donglun2010 2015-08-27 11:30
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?