Skip to content

Instantly share code, notes, and snippets.

@actsasbuffoon
Created March 19, 2011 17:24
Show Gist options
  • Save actsasbuffoon/877637 to your computer and use it in GitHub Desktop.
Save actsasbuffoon/877637 to your computer and use it in GitHub Desktop.
A strange issue with Date and the CSV stdlib.
ruby-1.9.2-p180 :001 > require 'Date'
=> true
# The date parses as it should.
ruby-1.9.2-p180 :002 > Date.parse '1/2/1903'
=> #<Date: 1903-02-01 (4832293/2,0,2299161)>
# Requiring the CSV stdlib causes a whole mess of conflicts with Date.
ruby-1.9.2-p180 :003 > require 'csv'
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:236: warning: already initialized constant MONTHNAMES
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:242: warning: already initialized constant DAYNAMES
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:245: warning: already initialized constant ABBR_MONTHNAMES
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:249: warning: already initialized constant ABBR_DAYNAMES
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:301: warning: already initialized constant ITALY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:305: warning: already initialized constant ENGLAND
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:309: warning: already initialized constant JULIAN
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:313: warning: already initialized constant GREGORIAN
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:315: warning: already initialized constant HALF_DAYS_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:316: warning: already initialized constant HOURS_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:317: warning: already initialized constant MINUTES_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:318: warning: already initialized constant SECONDS_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:319: warning: already initialized constant MILLISECONDS_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:320: warning: already initialized constant NANOSECONDS_IN_DAY
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:321: warning: already initialized constant MILLISECONDS_IN_SECOND
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:322: warning: already initialized constant NANOSECONDS_IN_SECOND
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:324: warning: already initialized constant MJD_EPOCH_IN_AJD
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:325: warning: already initialized constant UNIX_EPOCH_IN_AJD
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:326: warning: already initialized constant MJD_EPOCH_IN_CJD
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:327: warning: already initialized constant UNIX_EPOCH_IN_CJD
/Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:328: warning: already initialized constant LD_EPOCH_IN_CJD
=> true
# Now Date can't parse the same string it was successful with a minute ago.
ruby-1.9.2-p180 :004 > Date.parse '1/2/1903'
ArgumentError: invalid date
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/Date.rb:809:in `civil'
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:1810:in `today'
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:895:in `complete_frags'
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:1020:in `new_by_frags'
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/date.rb:1066:in `parse'
from (irb):4
from /Users/michaeltomer/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment