Gemspec 中的日期格式规范无效

当我尝试在窗口中使用 gem 时,我得到了下面的错误,我还提到 这个堆栈溢出的帖子和更新的红宝石和轨道。但是没有什么可以解决这个问题。

以下是完全错误,

D:\>gem env
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00
.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/execjs-1.2.4.gemspec]: invalid date format in specification: "2011-08-03 00:00:
00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/temple-0.3.3.gemspec]: invalid date format in specification: "2011-08-26 00:00:
00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/guard-0.6.3.gemspec]: invalid date format in specification: "2011-09-01 00:00:0
0.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/guard-livereload-0.3.1.gemspec]: invalid date format in specification: "2011-09
-01 00:00:00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/rack-cache-1.0.3.gemspec]: invalid date format in specification: "2011-08-27 00
:00:00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00
.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/execjs-1.2.4.gemspec]: invalid date format in specification: "2011-08-03 00:00:
00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/temple-0.3.3.gemspec]: invalid date format in specification: "2011-08-26 00:00:
00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/guard-0.6.3.gemspec]: invalid date format in specification: "2011-09-01 00:00:0
0.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/guard-livereload-0.3.1.gemspec]: invalid date format in specification: "2011-09
-01 00:00:00.000000000Z"
Invalid gemspec in [D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications
/rack-cache-1.0.3.gemspec]: invalid date format in specification: "2011-08-27 00
:00:00.000000000Z"
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
- INSTALLATION DIRECTORY: D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8
- RUBY EXECUTABLE: D:/RailsInstaller/Ruby1.8.7/bin/ruby.exe
- EXECUTABLE DIRECTORY: D:/RailsInstaller/Ruby1.8.7/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8
- C:/Documents and Settings/jeygokul/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
40993 次浏览

I have fixed this issue by upgrading my RubyGems to 1.8.10 with

gem update --system

Edit: You can also try (as suggested by ZeissS)

gem install rubygems-update
update_rubygems

In addition to running gem update --system I used gem install <gem with bad gemspec> on each of the item gem env reported as bad. This cleaned up the errors on my machine.

As Michael said in the comment:

gem pristine --all

None of these solutions worked for me. To fix it, I removed all the content of the mentioned directory (some/path/to/specification/) then I installed the gems I need (actually, Bundler then bundle install).

I just had the same problem on my ubuntu after upgrading to 10.10. None of the above worked for me. I had to install the update_rubygems script from http://rubygems.org/pages/download and run it once. Afterwords everything worked.

The ultimate solution is this:

Search "spec" files in your Ruby directory: *C:\Ruby187\lib\ruby\gems\1.8\specifications*

If a gemspec file contains something like this: s.date = %q{2011-10-13 00:00:00.000000000Z} Then delete the 00:00:00.000000000Z part: s.date = %q{2011-10-13}

After saving those gemspec files, the problem is solved.

Solved by running gem update --system then gem update.

Had the same problem when trying to install a GEM on Ubuntu 11.10.

Invalid gemspec in [/var/lib/gems/1.8/specifications/svn2git-2.1.2.gemspec]: invalid date format in specification: "2011-12-28 00:00:00.000000000Z"

The above options did not work for me. gem env reported the following:

RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]

So I presumed this problem was due to the fact I required a newer version of RubyGems installed.

Issuing gem update --system yeilded the following warning:

ERROR:  gem update --system is disabled on Debian, because it will overwrite the content of the rubygems Debian package, and might break your Debian system in subtle ways. The Debian-supported way to update rubygems is through apt-get, using Debian official repositories.
If you really know what you are doing, you can still update rubygems by setting the REALLY_GEM_UPDATE_SYSTEM environment variable, but please remember that this is completely unsupported by Debian.

However I was finally able to update rubygems to 1.8.15 by issuing:

sudo gem install rubygems-update && update_rubygems

Everything worked after that, good luck! :)

In my case, the referenced gem versions weren't even installed. I had those gems, but not the versions who's gemspecs were causing the error. So, I just deleted each of the /path/to/specifications/offending-X.Y.ZZ.gemspec files.

The various solutions noted in these answers did not work for me. What did work was re-installing the specific versions of the offending gem's. In your case that would of looked like:

gem install tilt   -v 1.3.3
gem install execjs -v 1.2.4
gem install temple -v 0.3.3
gem install guard  -v 0.6.3
gem install guard-livereload -v 0.3.1
gem install rack-cache -v 1.0.3

I think that gem pristine xxx yyy zzz or gem pristine --all might not be going out always (ever?) to the gem repositories whereas gem install xxx -v v.r.m does.

Anyway, re-installing the offending versions of the gems worked for me, although it was tedious...

I have fixed this issue 'invalid date formate specification' by, changing the corresponding line in D:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/specifications/tilt-1.3.3.gemspec by putting s.date =Time.now instead of s.date = "2011-08-25 00:00:00.000000000Z" The same can be use the other files too.

This is not really an answer but if somebody feels like digging more I found this gemspec spec here: http://rubygems.rubyforge.org/rubygems-update/Gem/Specification.html (scroll down to date=date() and click to show source):

@date = case date
when String then
if %r\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
Time.utc($1.to_i, $2.to_i, $3.to_i)
else
raise(Gem::InvalidSpecificationException,
"invalid date format in specification: #{date.inspect}")
end
when Time, Date then
Time.utc(date.year, date.month, date.day)
else
TODAY
end

So I guess this is the code that parses that gemspec, and it just looks like the date format that are in the files that show errors don't conform to this.

What I did was to just manually fix those offending gemspecs as suggested above (changing the dates to "yyyy-mm-dd", it works for me.

All the rubygem specs I had that had this problem also has a line

s.rubygems_version = %q{1.3.5}

So I'm guessing these are just old gems? And what's with those %q{...} anyway?

I've too many gems to fix one by one, and try both update_rubygems and gem pristine --all still no luck.

So I use rvm clear gemset to remove all gems with wrong gemspec. Execute bundle install to reinstall all the gems, and Viola!

Invalid gemspec in [/var/lib/gems/1.8/specifications/chronic-0.6.4.gemspec]: invalid date format in specification: "2011-09-09 00:00:00.000000000Z"

The simple fix to such kind of problem is to navigate to the file.. for eg.

Step 1. cd /var/lib/gems/1.8/specifications
step 2. open the file(chronic-0.6.4.gemspec) in editor of ur choice... (gedit chronic-0.6.4.gemspec)
step 3. change the s.date = %q{2011-10-13 00:00:00.000000000Z} to s.date = %q{2011-10-13}

Cheers :)

rvm gemset clear and then bundle install worked for me!

"gem install rubygems-update", "update_rubygems", then "gem pristine --all" is the combination that solved the problem for me after none of the previously listed ones worked.

If you had this error on Ubuntu 11.04 my solution was the following command lines:

$ sudo apt-get install ruby1.9.1

After doing this you will not get the date error.

cd vendor/bundle/ruby/1.9.x/specifications
sed -i 's/ 00\:00\:00.000000000Z//g' *