I run this in console:>> 110.years.ago.to_datetime=> Fri, 14 Mar 1902 01:20:12 +0000 Today is the 13th of march. So why is it returning 14th? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What is your timezone? for timezone 0 is 14 =) 2012/3/13 John Merlino <stoicism1-YDxpq3io04c@public.gmane.org>> > I run this in console: > > >> 110.years.ago.to_datetime > => Fri, 14 Mar 1902 01:20:12 +0000 > > Today is the 13th of march. So why is it returning 14th? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Fernando Almeida www.fernandoalmeida.net -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
110.years.ago.to_datetime.in_time_zone(-3) => Thu, 13 Mar 1902 22:29:48 LMT -03:06 2012/3/13 Fernando Almeida <fernando-7WGqr3rU1tV1NwFxuVVnt9HuzzzSOjJt@public.gmane.org>> What is your timezone? for timezone 0 is 14 =) > > > 2012/3/13 John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> > >> >> I run this in console: >> >> >> 110.years.ago.to_datetime >> => Fri, 14 Mar 1902 01:20:12 +0000 >> >> Today is the 13th of march. So why is it returning 14th? >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > Fernando Almeida > www.fernandoalmeida.net >-- Fernando Almeida www.fernandoalmeida.net -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting John Merlino <stoicism1-YDxpq3io04c@public.gmane.org>:> > I run this in console: > > >> 110.years.ago.to_datetime > => Fri, 14 Mar 1902 01:20:12 +0000 > > Today is the 13th of march. So why is it returning 14th? >Time zones. Notice the +0000 at the end. You are in the Pacific time zone according to the headers in your e-mail (assuming the list server hasn''t mangled them). So Fri, 14 Mar 1902 01:20:12 +0000 is Thu, 13 Mar 1902 18:20:12 -0700 Probably your Rails in configured to use UTC as the default timezone. $ cd config/ $ grep UTC * environment.rb: config.time_zone = ''UTC'' environment.rb~: config.time_zone = ''UTC'' HTH, Jeffrey -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Almeida wrote in post #1051362:> What is your timezone? for timezone 0 is 14 =)Yea. Date math is way more complicated than one might originally guess. Explains why there''s about 15 different Date and Calendar implementations in Java and very few of them are accurate over long time periods. I don''t really know how accurate Ruby''s implementation is. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
There wont be a specific timezone, people will use it in all timezones and so I would need it to work for everyone. This issue started for me when I had this: validates_inclusion_of :date_of_birth, :in => 110.years.ago.to_datetime..60.years.ago.to_datetime, :message => :invalid_age, :allow_nil => true So I trried to add date of birth of 110 years exactly, and it said it was an invalid age even though I specify above 110 years ago is ok. Then I try this: validates_inclusion_of :date_of_birth, :in => (110.years.ago.to_datetime - 1.days).. 60.years.ago.to_datetime, :message => :invalid_age, :allow_nil => true And thats when it gives me wrong date. My environment is already set to UTC: config.time_zone = ''UTC'' thanks for response -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 March 2012 15:42, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> There wont be a specific timezone, people will use it in all timezones > and so I would need it to work for everyone.You are missing the point, unfortunately you seem to have broken the thread and lost your original example, but the calculation 110.years.ago gave you /exactly/ the right answer (to the second), the reason it looked wrong is that you were not looking at the time zone of the answer, so at first glance it looked wrong. If you make sure that you display the answer in the same time zone as the original then it will be what you want. Colin> > This issue started for me when I had this: > > > validates_inclusion_of :date_of_birth, :in => > 110.years.ago.to_datetime..60.years.ago.to_datetime, :message > => :invalid_age, :allow_nil => true > > > So I trried to add date of birth of 110 years exactly, and it said it > was an invalid age even though I specify above 110 years ago is ok. > > Then I try this: > > > validates_inclusion_of :date_of_birth, :in => > (110.years.ago.to_datetime - 1.days).. > 60.years.ago.to_datetime, :message => :invalid_age, :allow_nil => true > > And thats when it gives me wrong date. > > My environment is already set to UTC: > > config.time_zone = ''UTC'' > > thanks for response > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- gplus.to/clanlaw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 15, 3:42 pm, John Merlino <stoici...-YDxpq3io04c@public.gmane.org> wrote:> And thats when it gives me wrong date. > > My environment is already set to UTC: > > config.time_zone = ''UTC'' > > thanks for responseThat''s why the answer was march 14th. You say that the date was march 13th 2012, but in the timezone you were doing your calculations in it was already march 14th Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.