问题
On my OS X 10.7.3 (Lion) laptop, I cannot parse JavaScript date strings with Qt WebKit using the Date constructor. Using either jasmine-headless-webkit or phantomJS, all calls like:
new Date("2012-04-10")
always return
"Invalid Date"
instead of a valid Date object. A few weeks back, everything was working fine, and I've checked this on half a dozen computers with a similar setup and cannot reproduce the problem anywhere else.
I am fairly certain the problems started when I decided to clear out my old supposedly-unused MacPorts installation (I have long since switched to Homebrew and was doing some house cleaning). I suspect there is a dynamically linked library that has been removed from my system, which is used by Qt for date parsing.
Does anyone have any idea what this date parsing library might be called? Any idea if I can install it with Homebrew or somehow manually repair the missing dependency?
I have tried reinstalling Qt and many other libraries, but nothing has fixed the problem.
回答1:
I don't have a Mac but given a similar situation for Windows, I would use a program that can report information on an application's dependencies like Dependency Walker. A quick search suggested this program might help in the Mac world.
回答2:
Ok, I resolved the problem with date parsing with jasmine-headless-webkit. Unfortunately, I wasn't scientific enough about it, so I'm not exactly sure what fixed it. It was likely some or all of the following process:
- Removing all traces of Qt from /Library/Frameworks/Qt* and homebrew (/usr/local/Qt* and /usr/local/Cellar/qt*)
- Reinstall the Qt libraries from http://qt.nokia.com/downloads/ (the libraries, not the SDK at the top)
- Update homebrew via "brew update"
- brew install qt
Additionally I installed the Qt SDK and XCode 4.3, but I don't think this fixed it because my coworkers do not have these things installed and weren't having the same problem as me.
There's a possibility this had nothing to do with MacPorts but might have had something to do with my older Qt 4.7 installation. I am now running Qt 4.8.
Sorry for all the noise! Maybe this info will help someone else.
回答3:
It looks like this bug is due to be fixed in v1.8, according to issue 187 "PhantomJS seems to break on ISO8601 Date format":
http://code.google.com/p/phantomjs/issues/detail?id=187
In the meantime, a workaround from that bug report is to append "T00:00:00Z" to your date.
回答4:
I had this error, I assume related to QtWebKit but when using wicked_pdf. It was hard to suss out the dependencies on wkhtmltopdf and qtwebkit across OSes (I run OSX in dev, sometimes Ubuntu in dev, we deploy to Heroku but may deploy to other platforms soon), so I punted and used a workaround as well. I used moment.js to new up a Date object and everything worked. I haven't had time to look under the hood and see how it works, but my guess is that moment.js is smart about turning "YYYY-MM-DD" into a date object by testing browser support.
This is actually a pretty good workaround for this when you want to not care about which OS your code is running in and can afford to include the moment.js lib. This way you don't have to care about which WebKit is running.
来源:https://stackoverflow.com/questions/10098731/new-dateyyyy-mm-dd-stopped-working-in-qt-webkit-after-removing-macports