I''m trying to add some extra methods to the time class by opening it up like this: class Time # opening up ruby time ONE_DAY_IN_SECS = 86400 def self.yesterday_at_midnight(today = Time.now) time_yesterday = today.to_i - ONE_DAY_IN_SECS yesterday = Time.at( time_yesterday ) return "#{yesterday.year}-#{yesterday.month_with_leading_zero}- #{yesterday.day_with_leading_zero} " end # ... etc end When I run my test from within NetBeans 6.0.1... require ''test/unit'' class TimeTest < Test::Unit::TestCase MONDAY_05_05_2008 = 1209972973 def test_can_open_time_to_add_yesterday_at_midnight today = Time.yesterday_at_midnight(Time.at(MONDAY_05_05_2008)) expected = "2008-05-04" assert( expected == today) end end This works and I get a passing test. However if I include an additional require line in my test: require ''unit_test_helper'' then I get the following error: C:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:92:in `load_specification'': undefined method `parse'' for Time:Class (NoMethodError) from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 314:in `date='' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 416:in `send'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 416:in `initialize'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 412:in `each'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb: 412:in `initialize'' from (eval):1:in `new'' from (eval):1:in `load_specification'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb: 128:in `eval'' ... 11 levels... from C:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:211:in `synchronize'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:211:in `searcher'' from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 30:in `require'' from C:/dev/esp/test/unit/models/time_test.rb:2 I think this has something to do with not requiring time properly, but I can''t work it out. Has anyone has a similar problem? Jules --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I managed to solve my problem using the Chronic library. http://chronic.rubyforge.org/ irb(main):002:0> require ''chronic'' => true irb(main):003:0> Chronic.parse(''yesterday'') => Tue May 06 12:00:00 +1000 2008 irb(main):004:0> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Um... Time.now.yesterday = This time yesterday Therefore, Time.now.yesterday.beginning_of_day = Midnight, yesterday. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yep, your logic is sound. On sqlite3, doing a select with the date ''2008-05-07'' defaults to midnight. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---