Permalink
Browse files

Merge pull request #23 from p/string-spec-date

Parse string dates in specifications
  • Loading branch information...
2 parents 990b908 + aa13976 commit 94eda4846387334abe0e9202da94a241a1dc624e @rtomayko committed Sep 11, 2011
Showing with 8 additions and 0 deletions.
  1. +8 −0 rpg-package-spec.rb
View
@@ -69,6 +69,14 @@
case spec['date']
when Time; spec['date'].utc.strftime('%Y-%m-%d')
when Date; spec['date'].to_s
+ when String
+ # Some date formats are not parsed by YAML despite being legitimate;
+ # e.g. 2011-08-25 00:00:00.000000000Z.
+ # Use Time.parse to parse such dates.
+ # Sadly, it looks like Time.parse will silently accept any garbage
+ # fed to it, meaning truly invalid input is unlikely to be caught.
+ require 'time'
+ Time.parse(spec['date']).utc.strftime('%Y-%m-%d')
else fail "unexpected date value: #{spec['date'].inspect}"
end
spec.reject! { |k,v| v.respond_to?(:ivars) }

0 comments on commit 94eda48

Please sign in to comment.