aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-07-03 01:39:54 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2010-07-03 02:13:44 -0300
commit201f373e7a183f33264ae31e7ca66768dddd3ebe (patch)
tree8e37b9e01841bcb9c017b5b40bdcd834866d7b40 /activesupport/lib/active_support/core_ext/date
parent8cc746331c32a6951e5c73c8a21fd32f00680471 (diff)
downloadrails-201f373e7a183f33264ae31e7ca66768dddd3ebe.tar.gz
rails-201f373e7a183f33264ae31e7ca66768dddd3ebe.tar.bz2
rails-201f373e7a183f33264ae31e7ca66768dddd3ebe.zip
Refactor move some date, time and date_time methods to */zones and fixed some requires
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb18
-rw-r--r--activesupport/lib/active_support/core_ext/date/zones.rb21
3 files changed, 23 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 28fec5394f..e6a213625c 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -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'
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb
index ba17b0a06b..48d474dd9a 100644
--- a/activesupport/lib/active_support/core_ext/date/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -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 @@ class Date
::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 @@ class Date
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
diff --git a/activesupport/lib/active_support/core_ext/date/zones.rb b/activesupport/lib/active_support/core_ext/date/zones.rb
new file mode 100644
index 0000000000..722f086951
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/date/zones.rb
@@ -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