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.

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

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题