13 @utc = time.respond_to?(:first) ? time.first : time
14 @micro = time.respond_to?(:last) ? time.last : 0
16 tv = Platform::POSIX::TimeVal.new
18 if 0 != Platform::POSIX.gettimeofday(tv.pointer, nil)
28 @local = @utc - Platform::POSIX.timezone
38 def initialize(moment)
40 # HACK. the 0 should be 1 if this Moment is during DST
41 @timezone = Platform::POSIX.tzname(0)
62 # See http://www.hermetic.ch/cal_stud/jdn.htm
65 l = l - (146097*n+3) / 4
66 i = 4000 * (l+1) / 1461001
67 l = l - 1461 * i / 4 + 31
72 i = 100 * (n - 49) + i + l
78 # HACK this only does gregorian weeks
79 @weekday = Days[(@jd + 1) % 7]
83 @year % 4 == 0 && @year % 100 != 0 || @year % 400 == 0
86 # HACK these need to be locale specific tables
98 ShortWeekday[@weekday]
161 offset = @moment.offset / 3600
179 return @human if @human
182 h = HumanTime.new(self)
185 h.second = (s % 60); s /= 60
186 h.minute = (s % 60); s /= 60
191 @mjd = EpochToMDJ + u
193 # The julian day began an noon, not midnight.
204 :a => :short_weekday,
208 :c => :locale_datetime,
213 :g => :padded_short_commercial_year,
214 :G => :commercial_year,
215 :H => :padded_hour_24,
219 :k => :bpadded_hour_24,
221 :M => :padded_minute,
227 :S => :padded_second,
231 :U => :week_from_sunday,
233 :V => :week_from_monday,
239 :y => :padded_short_year,
247 pattern = /%([#{FormatMethod.keys.join}])/o
248 str.gsub(pattern) do |which|
249 h.__send__ FormatMethod[$1.to_sym]
255 format "%a %b %d %H:%M:%S %Z %Y"
257 format "%a %b %d %H:%M:%S UTC %Y"
261 alias_method :inspect, :to_s