From: sto.mar@... Date: 2012-12-10T21:47:52+09:00 Subject: Re: Time.new(2001, 12, 3).to_i returns wrong value Am 09.12.2012 15:07, schrieb Robert Buck: > I am doing something that not many do, I am writing a database driver > for our database, and an active record adapter. > > I am having difficulty with Date and Time. Namely, the Ruby doc clearly > states that it represents times internally in UTC seconds since the > common epoch. However, if you look at the Ruby C code clearly this is > not the case, or at least, all operations are performed relative to the > default timezone. For instance: > > Time.new(2001, 12, 3).to_i Time.new uses the system time zone by default: [10] pry(main)> time = Time.new(2001, 12, 3) => 2001-12-03 00:00:00 +0600 [11] pry(main)> time.to_i => 1007316000 [12] pry(main)> time = Time.new(2001, 12, 3, 0, 0, 0, '+00:00') => 2001-12-03 00:00:00 +0000 [13] pry(main)> time.to_i => 1007337600 Or you can use Time.utc: [26] pry(main)> time = Time.utc(2001, 12, 3) => 2001-12-03 00:00:00 UTC [27] pry(main)> time.to_i => 1007337600 > According to international standards this OUGHT to return 1007337600, > but no, it returns 1007355600, despite the Ruby documentation stating > that the to_i method is supposed to return seconds since the Epoch. --