2008-03-30 18:24:35 -04:00
|
|
|
require 'tzinfo'
|
2008-11-23 19:08:00 -05:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
module ActiveSupport
|
2008-09-11 06:51:16 -04:00
|
|
|
# A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
|
2008-05-25 07:29:00 -04:00
|
|
|
# limited to UTC and the system's <tt>ENV['TZ']</tt> zone.
|
2008-05-18 15:13:47 -04:00
|
|
|
#
|
2008-05-25 07:29:00 -04:00
|
|
|
# You shouldn't ever need to create a TimeWithZone instance directly via <tt>new</tt> -- instead, Rails provides the methods
|
|
|
|
# +local+, +parse+, +at+ and +now+ on TimeZone instances, and +in_time_zone+ on Time and DateTime instances, for a more
|
2008-05-18 15:13:47 -04:00
|
|
|
# user-friendly syntax. Examples:
|
|
|
|
#
|
|
|
|
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
|
|
|
|
# Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
|
|
|
|
# Time.zone.parse('2007-02-01 15:30:45') # => Sat, 10 Feb 2007 15:30:45 EST -05:00
|
|
|
|
# Time.zone.at(1170361845) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
|
|
|
|
# Time.zone.now # => Sun, 18 May 2008 13:07:55 EDT -04:00
|
|
|
|
# Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45 EST -05:00
|
|
|
|
#
|
|
|
|
# See TimeZone and ActiveSupport::CoreExtensions::Time::Zones for further documentation for these methods.
|
|
|
|
#
|
|
|
|
# TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangable. Examples:
|
|
|
|
#
|
|
|
|
# t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00
|
|
|
|
# t.hour # => 13
|
|
|
|
# t.dst? # => true
|
|
|
|
# t.utc_offset # => -14400
|
|
|
|
# t.zone # => "EDT"
|
|
|
|
# t.to_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
|
|
|
|
# t + 1.day # => Mon, 19 May 2008 13:27:25 EDT -04:00
|
|
|
|
# t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00 EST -05:00
|
|
|
|
# t > Time.utc(1999) # => true
|
|
|
|
# t.is_a?(Time) # => true
|
|
|
|
# t.is_a?(ActiveSupport::TimeWithZone) # => true
|
2008-01-22 20:56:22 -05:00
|
|
|
class TimeWithZone
|
|
|
|
include Comparable
|
|
|
|
attr_reader :time_zone
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-03-16 22:40:28 -04:00
|
|
|
def initialize(utc_time, time_zone, local_time = nil, period = nil)
|
|
|
|
@utc, @time_zone, @time = utc_time, time_zone, local_time
|
|
|
|
@period = @utc ? period : get_period_and_ensure_valid_local_time
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Returns a Time or DateTime instance that represents the time in +time_zone+.
|
2008-01-22 20:56:22 -05:00
|
|
|
def time
|
2008-03-27 22:10:36 -04:00
|
|
|
@time ||= period.to_local(@utc)
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Returns a Time or DateTime instance that represents the time in UTC.
|
2008-01-22 20:56:22 -05:00
|
|
|
def utc
|
2008-03-27 22:10:36 -04:00
|
|
|
@utc ||= period.to_utc(@time)
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
|
|
|
alias_method :comparable_time, :utc
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :getgm, :utc
|
|
|
|
alias_method :getutc, :utc
|
|
|
|
alias_method :gmtime, :utc
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Returns the underlying TZInfo::TimezonePeriod.
|
2008-01-22 20:56:22 -05:00
|
|
|
def period
|
2008-03-16 22:40:28 -04:00
|
|
|
@period ||= time_zone.period_for_utc(@utc)
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Returns the simultaneous time in <tt>Time.zone</tt>, or the specified zone.
|
2008-03-17 01:50:13 -04:00
|
|
|
def in_time_zone(new_zone = ::Time.zone)
|
2008-02-10 15:35:47 -05:00
|
|
|
return self if time_zone == new_zone
|
2008-01-22 20:56:22 -05:00
|
|
|
utc.in_time_zone(new_zone)
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Returns a <tt>Time.local()</tt> instance of the simultaneous time in your system's <tt>ENV['TZ']</tt> zone
|
2008-01-22 20:56:22 -05:00
|
|
|
def localtime
|
2008-02-10 15:04:14 -05:00
|
|
|
utc.getlocal
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :getlocal, :localtime
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def dst?
|
2008-01-25 13:23:22 -05:00
|
|
|
period.dst?
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :isdst, :dst?
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def utc?
|
2008-01-25 13:23:22 -05:00
|
|
|
time_zone.name == 'UTC'
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :gmt?, :utc?
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def utc_offset
|
2008-01-25 13:23:22 -05:00
|
|
|
period.utc_total_offset
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :gmt_offset, :utc_offset
|
|
|
|
alias_method :gmtoff, :utc_offset
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def formatted_offset(colon = true, alternate_utc_string = nil)
|
|
|
|
utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
|
2008-01-22 20:56:22 -05:00
|
|
|
def zone
|
2008-03-21 18:48:00 -04:00
|
|
|
period.zone_identifier.to_s
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def inspect
|
|
|
|
"#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
|
|
|
|
end
|
|
|
|
|
2009-01-10 09:09:29 -05:00
|
|
|
def xmlschema(fraction_digits = 0)
|
|
|
|
fraction = if fraction_digits > 0
|
|
|
|
".%i" % time.usec.to_s[0, fraction_digits]
|
|
|
|
end
|
|
|
|
|
|
|
|
"#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}"
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :iso8601, :xmlschema
|
2008-07-16 08:00:36 -04:00
|
|
|
|
|
|
|
# Returns a JSON string representing the TimeWithZone. If ActiveSupport.use_standard_json_time_format is set to
|
|
|
|
# true, the ISO 8601 format is used.
|
|
|
|
#
|
2009-01-18 13:10:58 -05:00
|
|
|
# ==== Examples
|
2008-07-16 08:00:36 -04:00
|
|
|
#
|
|
|
|
# # With ActiveSupport.use_standard_json_time_format = true
|
|
|
|
# Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
|
|
|
|
# # => "2005-02-01T15:15:10Z"
|
|
|
|
#
|
|
|
|
# # With ActiveSupport.use_standard_json_time_format = false
|
|
|
|
# Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
|
|
|
|
# # => "2005/02/01 15:15:10 +0000"
|
2008-01-22 20:56:22 -05:00
|
|
|
def to_json(options = nil)
|
2008-04-12 17:48:56 -04:00
|
|
|
if ActiveSupport.use_standard_json_time_format
|
2008-05-12 22:02:04 -04:00
|
|
|
xmlschema.inspect
|
2008-04-12 17:48:56 -04:00
|
|
|
else
|
|
|
|
%("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
|
|
|
|
end
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 17:26:16 -05:00
|
|
|
def to_yaml(options = {})
|
2008-03-23 00:44:50 -04:00
|
|
|
if options.kind_of?(YAML::Emitter)
|
|
|
|
utc.to_yaml(options)
|
|
|
|
else
|
|
|
|
time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
|
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 15:04:14 -05:00
|
|
|
def httpdate
|
|
|
|
utc.httpdate
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 15:04:14 -05:00
|
|
|
def rfc2822
|
|
|
|
to_s(:rfc822)
|
|
|
|
end
|
|
|
|
alias_method :rfc822, :rfc2822
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-02 09:45:23 -04:00
|
|
|
# <tt>:db</tt> format outputs time in UTC; all others output time in local.
|
|
|
|
# Uses TimeWithZone's +strftime+, so <tt>%Z</tt> and <tt>%z</tt> work correctly.
|
2008-09-11 06:51:16 -04:00
|
|
|
def to_s(format = :default)
|
2008-01-22 20:56:22 -05:00
|
|
|
return utc.to_s(format) if format == :db
|
|
|
|
if formatter = ::Time::DATE_FORMATS[format]
|
|
|
|
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
|
|
|
else
|
|
|
|
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
|
|
|
|
end
|
|
|
|
end
|
2009-01-26 10:10:41 -05:00
|
|
|
alias_method :to_formatted_s, :to_s
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-02 09:45:23 -04:00
|
|
|
# Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to
|
2008-01-22 20:56:22 -05:00
|
|
|
# Time#strftime, so that zone information is correct
|
|
|
|
def strftime(format)
|
|
|
|
format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false))
|
|
|
|
time.strftime(format)
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Use the time in UTC for comparisons.
|
2008-01-22 20:56:22 -05:00
|
|
|
def <=>(other)
|
|
|
|
utc <=> other
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-16 19:35:49 -05:00
|
|
|
def between?(min, max)
|
|
|
|
utc.between?(min, max)
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
|
|
|
def past?
|
|
|
|
utc.past?
|
|
|
|
end
|
|
|
|
|
|
|
|
def today?
|
2008-09-14 23:56:32 -04:00
|
|
|
time.today?
|
2008-09-11 06:51:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def future?
|
|
|
|
utc.future?
|
|
|
|
end
|
|
|
|
|
2008-02-10 17:26:16 -05:00
|
|
|
def eql?(other)
|
|
|
|
utc == other
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-16 18:15:59 -05:00
|
|
|
def +(other)
|
2008-06-29 16:17:51 -04:00
|
|
|
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
|
|
|
|
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
|
|
|
|
if duration_of_variable_length?(other)
|
|
|
|
method_missing(:+, other)
|
|
|
|
else
|
|
|
|
result = utc.acts_like?(:date) ? utc.since(other) : utc + other rescue utc.since(other)
|
|
|
|
result.in_time_zone(time_zone)
|
|
|
|
end
|
2008-02-16 18:15:59 -05:00
|
|
|
end
|
2008-06-29 16:17:51 -04:00
|
|
|
|
2008-01-25 19:34:44 -05:00
|
|
|
def -(other)
|
2008-06-29 16:17:51 -04:00
|
|
|
# If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time,
|
|
|
|
# otherwise move backwards #utc, for accuracy when moving across DST boundaries
|
2008-02-16 18:15:59 -05:00
|
|
|
if other.acts_like?(:time)
|
2009-01-04 14:58:08 -05:00
|
|
|
utc.to_f - other.to_f
|
2008-06-29 16:17:51 -04:00
|
|
|
elsif duration_of_variable_length?(other)
|
|
|
|
method_missing(:-, other)
|
2008-02-16 18:15:59 -05:00
|
|
|
else
|
2008-05-18 12:15:29 -04:00
|
|
|
result = utc.acts_like?(:date) ? utc.ago(other) : utc - other rescue utc.ago(other)
|
2008-04-12 18:31:29 -04:00
|
|
|
result.in_time_zone(time_zone)
|
2008-02-16 18:15:59 -05:00
|
|
|
end
|
2008-01-25 19:34:44 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-04-12 18:31:29 -04:00
|
|
|
def since(other)
|
2008-06-29 16:17:51 -04:00
|
|
|
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
|
|
|
|
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
|
|
|
|
if duration_of_variable_length?(other)
|
|
|
|
method_missing(:since, other)
|
|
|
|
else
|
|
|
|
utc.since(other).in_time_zone(time_zone)
|
|
|
|
end
|
2008-04-12 18:31:29 -04:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-04-12 18:31:29 -04:00
|
|
|
def ago(other)
|
2008-06-29 16:17:51 -04:00
|
|
|
since(-other)
|
2008-04-12 18:31:29 -04:00
|
|
|
end
|
2008-06-29 16:17:51 -04:00
|
|
|
|
2008-04-12 18:31:29 -04:00
|
|
|
def advance(options)
|
2008-06-29 16:26:56 -04:00
|
|
|
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
|
2008-06-29 16:17:51 -04:00
|
|
|
# otherwise advance from #utc, for accuracy when moving across DST boundaries
|
2009-02-10 00:12:47 -05:00
|
|
|
if options.values_at(:years, :weeks, :months, :days).any?
|
2008-06-29 16:17:51 -04:00
|
|
|
method_missing(:advance, options)
|
|
|
|
else
|
|
|
|
utc.advance(options).in_time_zone(time_zone)
|
|
|
|
end
|
2008-04-12 18:31:29 -04:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-09-15 00:07:48 -04:00
|
|
|
%w(year mon month day mday wday yday hour min sec to_date).each do |method_name|
|
2008-05-08 23:07:21 -04:00
|
|
|
class_eval <<-EOV
|
2008-12-28 14:48:05 -05:00
|
|
|
def #{method_name} # def year
|
|
|
|
time.#{method_name} # time.year
|
|
|
|
end # end
|
2008-05-08 23:07:21 -04:00
|
|
|
EOV
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-03-27 21:57:41 -04:00
|
|
|
def usec
|
|
|
|
time.respond_to?(:usec) ? time.usec : 0
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 15:04:14 -05:00
|
|
|
def to_a
|
2008-03-16 23:45:32 -04:00
|
|
|
[time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
|
2008-02-10 15:04:14 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 15:04:14 -05:00
|
|
|
def to_f
|
|
|
|
utc.to_f
|
2008-09-11 06:51:16 -04:00
|
|
|
end
|
|
|
|
|
2008-02-10 15:04:14 -05:00
|
|
|
def to_i
|
|
|
|
utc.to_i
|
|
|
|
end
|
2008-02-10 17:26:16 -05:00
|
|
|
alias_method :hash, :to_i
|
|
|
|
alias_method :tv_sec, :to_i
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-02 09:45:23 -04:00
|
|
|
# A TimeWithZone acts like a Time, so just return +self+.
|
2008-01-22 20:56:22 -05:00
|
|
|
def to_time
|
|
|
|
self
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-02-10 17:26:16 -05:00
|
|
|
def to_datetime
|
|
|
|
utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# So that +self+ <tt>acts_like?(:time)</tt>.
|
2008-01-22 20:56:22 -05:00
|
|
|
def acts_like_time?
|
|
|
|
true
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Say we're a Time to thwart type checking.
|
2008-01-22 20:56:22 -05:00
|
|
|
def is_a?(klass)
|
|
|
|
klass == ::Time || super
|
|
|
|
end
|
|
|
|
alias_method :kind_of?, :is_a?
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-01-22 20:56:22 -05:00
|
|
|
def freeze
|
2008-10-19 23:33:26 -04:00
|
|
|
period; utc; time # preload instance variables before freezing
|
|
|
|
super
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-03-02 22:49:37 -05:00
|
|
|
|
|
|
|
def marshal_dump
|
|
|
|
[utc, time_zone.name, time]
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-03-02 22:49:37 -05:00
|
|
|
def marshal_load(variables)
|
2008-08-31 16:15:26 -04:00
|
|
|
initialize(variables[0].utc, ::Time.__send__(:get_zone, variables[1]), variables[2].utc)
|
2008-03-02 22:49:37 -05:00
|
|
|
end
|
2008-05-31 17:54:17 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Ensure proxy class responds to all methods that underlying time instance responds to.
|
2008-05-31 17:54:17 -04:00
|
|
|
def respond_to?(sym, include_priv = false)
|
2008-02-16 18:15:59 -05:00
|
|
|
# consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
|
|
|
|
return false if sym.to_s == 'acts_like_date?'
|
2008-05-31 17:54:17 -04:00
|
|
|
super || time.respond_to?(sym, include_priv)
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-05-31 17:54:17 -04:00
|
|
|
|
2008-05-25 07:29:00 -04:00
|
|
|
# Send the missing method to +time+ instance, and wrap result in a new TimeWithZone with the existing +time_zone+.
|
2008-01-22 20:56:22 -05:00
|
|
|
def method_missing(sym, *args, &block)
|
2008-04-12 18:31:29 -04:00
|
|
|
result = time.__send__(sym, *args, &block)
|
|
|
|
result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
|
|
|
private
|
2008-03-16 22:40:28 -04:00
|
|
|
def get_period_and_ensure_valid_local_time
|
2008-09-11 06:51:16 -04:00
|
|
|
# we don't want a Time.local instance enforcing its own DST rules as well,
|
2008-03-17 01:07:50 -04:00
|
|
|
# so transfer time values to a utc constructor if necessary
|
|
|
|
@time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
|
|
|
|
begin
|
|
|
|
@time_zone.period_for_local(@time)
|
|
|
|
rescue ::TZInfo::PeriodNotFound
|
|
|
|
# time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again
|
|
|
|
@time += 1.hour
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-03-17 01:07:50 -04:00
|
|
|
def transfer_time_values_to_utc_constructor(time)
|
|
|
|
::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
|
2008-03-16 22:40:28 -04:00
|
|
|
end
|
2008-09-11 06:51:16 -04:00
|
|
|
|
2008-06-29 16:17:51 -04:00
|
|
|
def duration_of_variable_length?(obj)
|
2009-02-09 00:32:54 -05:00
|
|
|
ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :days].include? p[0] }
|
2008-06-29 16:17:51 -04:00
|
|
|
end
|
2008-01-22 20:56:22 -05:00
|
|
|
end
|
|
|
|
end
|