Permalink
Browse files

Refactor move some date, time and date_time methods to */zones and fi…

…xed some requires
  • Loading branch information...
1 parent 8cc7463 commit 201f373e7a183f33264ae31e7ca66768dddd3ebe @spastorino spastorino committed Jul 3, 2010
@@ -1,7 +1,8 @@
require 'date'
require 'active_support/duration'
-require 'active_support/core_ext/time/zones'
require 'active_support/core_ext/object/acts_like'
+require 'active_support/core_ext/date/zones'
+require 'active_support/core_ext/time/zones'
class Date
if RUBY_VERSION < '1.9'
@@ -1,6 +1,5 @@
require 'date'
require 'active_support/inflector'
-require 'active_support/core_ext/time/calculations'
class Date
DATE_FORMATS = {
@@ -15,9 +14,6 @@ class Date
# Ruby 1.9 has Date#to_time which converts to localtime only.
remove_method :to_time if instance_methods.include?(:to_time)
- # Ruby 1.9 has Date#xmlschema which converts to a string without the time component.
- remove_method :xmlschema if instance_methods.include?(:xmlschema)
-
# Convert to a formatted string. See DATE_FORMATS for predefined formats.
#
# This method is aliased to <tt>to_s</tt>.
@@ -82,16 +78,6 @@ def to_time(form = :local)
::Time.send("#{form}_time", year, month, day)
end
- # Converts Date to a TimeWithZone in the current zone if Time.zone_default is set,
- # otherwise converts Date to a Time via Date#to_time
- def to_time_in_current_zone
- if ::Time.zone_default
- ::Time.zone.local(year, month, day)
- else
- to_time
- end
- end
-
# Converts a Date instance to a DateTime, where the time is set to the beginning of the day
# and UTC offset is set to 0.
#
@@ -102,8 +88,4 @@ def to_time_in_current_zone
def to_datetime
::DateTime.civil(year, month, day, 0, 0, 0, 0)
end if RUBY_VERSION < '1.9'
-
- def xmlschema
- to_time_in_current_zone.xmlschema
- end
end
@@ -0,0 +1,21 @@
+require 'date'
+require 'active_support/core_ext/time/zones'
+
+class Date
+ # Converts Date to a TimeWithZone in the current zone if Time.zone_default is set,
+ # otherwise converts Date to a Time via Date#to_time
+ def to_time_in_current_zone
+ if ::Time.zone_default
+ ::Time.zone.local(year, month, day)
+ else
+ to_time
+ end
+ end
+
+ # Ruby 1.9 has Date#xmlschema which converts to a string without the time component.
+ remove_method :xmlschema if instance_methods.include?(:xmlschema)
+
+ def xmlschema
+ to_time_in_current_zone.xmlschema
+ end
+end
@@ -1,5 +1,6 @@
require 'rational' unless RUBY_VERSION >= '1.9.2'
require 'active_support/core_ext/object/acts_like'
+require 'active_support/core_ext/time/zones'
class DateTime
class << self
@@ -1,6 +1,7 @@
require 'active_support/inflector'
require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/date_time/calculations'
+require 'active_support/values/time_zone'
class DateTime
# Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/time/zones'
+
class DateTime
# Returns the simultaneous time in <tt>Time.zone</tt>.
#
@@ -40,6 +40,11 @@ def utc_time(*args)
def local_time(*args)
time_with_datetime_fallback(:local, *args)
end
+
+ # Returns <tt>Time.zone.now</tt> when <tt>config.time_zone</tt> is set, otherwise just returns <tt>Time.now</tt>.
+ def current
+ ::Time.zone_default ? ::Time.zone.now : ::Time.now
+ end
end
# Tells whether the Time object's time lies in the past
@@ -41,11 +41,6 @@ def use_zone(time_zone)
::Time.zone = old_zone
end
- # Returns <tt>Time.zone.now</tt> when <tt>config.time_zone</tt> is set, otherwise just returns <tt>Time.now</tt>.
- def current
- ::Time.zone_default ? ::Time.zone.now : ::Time.now
- end
-
private
def get_zone(time_zone)
return time_zone if time_zone.nil? || time_zone.is_a?(ActiveSupport::TimeZone)
@@ -24,6 +24,7 @@ module ActiveSupport
require 'active_support/core_ext/date/freeze'
require 'active_support/core_ext/date/calculations'
require 'active_support/core_ext/date/conversions'
+require 'active_support/core_ext/date/zones'
require 'active_support/core_ext/date_time/acts_like'
require 'active_support/core_ext/date_time/calculations'

0 comments on commit 201f373

Please sign in to comment.