Class: Time

Inherits:
Object show all
Includes:
ActiveSupport::CoreExtensions::Time::Behavior, ActiveSupport::CoreExtensions::Time::Calculations, ActiveSupport::CoreExtensions::Time::Conversions, ActiveSupport::CoreExtensions::Time::Zones
Defined in:
lib/active_support/core_ext/time.rb,
lib/active_support/core_ext/time.rb,
lib/active_support/json/encoders/time.rb

Overview

:nodoc:

Constant Summary

Constants included from ActiveSupport::CoreExtensions::Time::Conversions

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS

Constants included from ActiveSupport::CoreExtensions::Time::Calculations

ActiveSupport::CoreExtensions::Time::Calculations::COMMON_YEAR_DAYS_IN_MONTH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::Time::Zones

#in_time_zone, included

Methods included from ActiveSupport::CoreExtensions::Time::Conversions

#formatted_offset, included, #to_date, #to_datetime, #to_formatted_s, #to_time

Methods included from ActiveSupport::CoreExtensions::Time::Calculations

#advance, #ago, #beginning_of_day, #beginning_of_month, #beginning_of_quarter, #beginning_of_week, #beginning_of_year, #change, #compare_with_coercion, #end_of_day, #end_of_month, #end_of_quarter, #end_of_week, #end_of_year, #future?, included, #last_month, #last_year, #minus_with_coercion, #minus_with_duration, #months_ago, #months_since, #next_month, #next_week, #next_year, #past?, #plus_with_duration, #prev_month, #prev_year, #seconds_since_midnight, #since, #today?, #tomorrow, #years_ago, #years_since, #yesterday

Methods included from ActiveSupport::CoreExtensions::Time::Behavior

#acts_like_time?

Class Method Details

._load(marshaled_time) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/active_support/core_ext/time.rb', line 16

def _load(marshaled_time)
  time = _original_load(marshaled_time)
  time.instance_eval do
    if defined?(@marshal_with_utc_coercion)
      val = remove_instance_variable("@marshal_with_utc_coercion")
    end
    val ? utc : self
  end
end

._original_loadObject



15
# File 'lib/active_support/core_ext/time.rb', line 15

alias_method :_original_load, :_load

Instance Method Details

#_dump(*args) ⇒ Object



28
29
30
31
32
# File 'lib/active_support/core_ext/time.rb', line 28

def _dump(*args)
  obj = dup
  obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
  obj._original_dump(*args)
end

#_original_dumpObject



27
# File 'lib/active_support/core_ext/time.rb', line 27

alias_method :_original_dump, :_dump

#as_json(options = nil) ⇒ Object

Coerces the time to a string for JSON encoding.

ISO 8601 format is used if ActiveSupport::JSON::Encoding.use_standard_json_time_format is set.

Examples

# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
Time.utc(2005,2,1,15,15,10).to_json
# => "2005-02-01T15:15:10Z"

# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
Time.utc(2005,2,1,15,15,10).to_json
# => "2005/02/01 15:15:10 +0000"


15
16
17
18
19
20
21
# File 'lib/active_support/json/encoders/time.rb', line 15

def as_json(options = nil)
  if ActiveSupport::JSON::Encoding.use_standard_json_time_format
    xmlschema
  else
    %(#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
  end
end