提交 070c2423 编写于 作者: J Jeremy Kemper

Merge remote branch 'spastorino/master'

# -*- 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'
......
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'
......
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
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
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
......
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
......
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'
......
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册