Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'spastorino/master'

  • Loading branch information...
commit 070c24232f74c75b60757ff2bd3cc00ea662d5a6 2 parents 54250a5 + 075f8b7
@jeremy jeremy authored
View
1  activemodel/lib/active_model/errors.rb
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/reverse_merge'
View
3  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'
View
18 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 @@ 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
View
21 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
View
1  activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -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
View
1  activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -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
View
2  activesupport/lib/active_support/core_ext/date_time/zones.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/time/zones'
+
class DateTime
# Returns the simultaneous time in <tt>Time.zone</tt>.
#
View
5 activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -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
View
5 activesupport/lib/active_support/core_ext/time/zones.rb
@@ -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)
View
1  activesupport/lib/active_support/time.rb
@@ -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'
View
12 activesupport/lib/active_support/values/time_zone.rb
@@ -1,11 +1,5 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/try'
-begin
- require 'tzinfo'
-rescue LoadError => e
- $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
- raise e
-end
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
#
@@ -201,6 +195,12 @@ def self.seconds_to_utc_offset(seconds, colon = true)
# (GMT). Seconds were chosen as the offset unit because that is the unit that
# Ruby uses to represent time zone offsets (see Time#utc_offset).
def initialize(name, utc_offset = nil, tzinfo = nil)
+ begin
+ require 'tzinfo'
+ rescue LoadError => e
+ $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
+ raise e
+ end
@name = name
@utc_offset = utc_offset
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
Please sign in to comment.
Something went wrong with that request. Please try again.