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/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb,
lib/mack-facets/extensions/time.rb,
lib/gems/extlib-0.9.9/lib/extlib/time.rb,
lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb,
lib/gems/activesupport-2.2.2/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_formatted_s

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, #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
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb', line 16

def _load(marshaled_time)
  time = _original_load(marshaled_time)
  utc = time.instance_variable_get('@marshal_with_utc_coercion')
  utc ? time.utc : time
end

._original_loadObject



15
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb', line 15

alias_method :_original_load, :_load

.random(start_time, end_time = Time.now) ⇒ Object

Generates a random Time between the start time and the end time.



26
27
28
# File 'lib/mack-facets/extensions/time.rb', line 26

def self.random(start_time, end_time = Time.now)
  start_time + (rand(end_time - start_time).to_i)
end

Instance Method Details

#_dump(*args) ⇒ Object



24
25
26
27
28
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb', line 24

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

#_original_dumpObject



23
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/time.rb', line 23

alias_method :_original_dump, :_dump

#to_dateObject



7
8
9
10
11
# File 'lib/mack-facets/extensions/time.rb', line 7

def to_date
  require 'date' # just in case
  jd = Date.__send__(:civil_to_jd, year, mon, mday, Date::ITALY)
  Date.new!(Date.__send__(:jd_to_ajd, jd, 0, 0), 0, Date::ITALY)
end

#to_datetimeDateTime

Convert to DateTime (for DateTime/Time conversion protocol).

Time.now.to_datetime    #=> #<DateTime: 106046956823/43200,-1/3,2299161>

Returns:

  • (DateTime)

    DateTime object representing the same moment as receiver



38
39
40
# File 'lib/gems/extlib-0.9.9/lib/extlib/time.rb', line 38

def to_datetime
  raise NoMethodError.new("to_datetime")
end

#to_json(options = nil) ⇒ Object

Returns a JSON string representing the time. If ActiveSupport.use_standard_json_time_format is set to true, the ISO 8601 format is used.

Examples:

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

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


14
15
16
# File 'lib/gems/extlib-0.9.9/lib/extlib/time.rb', line 14

def to_json(*)
  self.xmlschema.to_json
end

#to_timeTime

Return receiver (for DateTime/Time conversion protocol).

Time.now.to_time        #=> Wed Nov 19 20:08:28 -0800 2008

Returns:

  • (Time)

    Receiver



26
27
28
# File 'lib/gems/extlib-0.9.9/lib/extlib/time.rb', line 26

def to_time
  self
end