instance method mon

Ruby on Rails edge

Since edge

Signature

mon(= time.mon)

No documentation comment.

Parameters

= time.mon req
Source
# File activesupport/lib/active_support/time_with_zone.rb, line 494
    def mon = time.mon

    def month = time.month

    def day = time.day

    def mday = time.mday

    def wday = time.wday

    def yday = time.yday

    def hour = time.hour

    def min = time.min

    def sec = time.sec

    def usec = time.usec

    def nsec = time.nsec

    def to_date = time.to_date

    # Returns Array of parts of Time in sequence of
    # [seconds, minutes, hours, day, month, year, weekday, yearday, dst?, zone].
    #
    # ```
    # now = Time.zone.now     # => Tue, 18 Aug 2015 02:29:27.485278555 UTC +00:00
    # now.to_a                # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"]
    # ```
    def to_a
      [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
    end

    # Returns the object's date and time as a floating-point number of seconds
    # since the Epoch (January 1, 1970 00:00 UTC).
    #
    # ```
    # Time.zone.now.to_f # => 1417709320.285418
    # ```
    def to_f
      utc.to_f
    end

    # Returns the object's date and time as an integer number of seconds
    # since the Epoch (January 1, 1970 00:00 UTC).
    #
    # ```
    # Time.zone.now.to_i # => 1417709320
    # ```
    def to_i
      utc.to_i
    end
    alias_method :tv_sec, :to_i

    # Returns the object's date and time as a rational number of seconds
    # since the Epoch (January 1, 1970 00:00 UTC).
    #
    # ```
    # Time.zone.now.to_r # => (708854548642709/500000)
    # ```
    def to_r
      utc.to_r
    end

    # Returns an instance of DateTime with the timezone's UTC offset
    #
    # ```
    # Time.zone.now.to_datetime                         # => Tue, 18 Aug 2015 02:32:20 +0000
    # Time.current.in_time_zone('Hawaii').to_datetime   # => Mon, 17 Aug 2015 16:32:20 -1000
    # ```
    def to_datetime
      @to_datetime ||= utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
    end

    # Returns an instance of `Time`, either with the same timezone as `self`,
    # with the same UTC offset as `self` or in the local system timezone
    # depending on the setting of `ActiveSupport.to_time_preserves_timezone`.
    def to_time
      @to_time_with_timezone ||= getlocal(time_zone)
    end

    # So that `self` `acts_like?(:time)`.
    def acts_like_time?
      true
    end

    # Say we're a Time to thwart type checking.
    def is_a?(klass)
      klass == ::Time || super
    end
    alias_method :kind_of?, :is_a?

    # An instance of ActiveSupport::TimeWithZone is never blank
    #: () -> false
    def blank?
      false
    end

    def present? # :nodoc:
      true
    end

    def freeze
      # preload instance variables before freezing
      period; utc; time; utc?; to_datetime; to_time
      super
    end

    def marshal_dump
      [utc, time_zone.name, time]
    end

    def marshal_load(variables)
      initialize(variables[0].utc, ::Time.find_zone(variables[1]), variables[2].utc)
    end

    # Ensure proxy class responds to all methods that underlying time instance
    # responds to.
    def respond_to_missing?(sym, include_priv)
      time.respond_to?(sym, include_priv)
    end

    # Send the missing method to `time` instance, and wrap result in a new
    # TimeWithZone with the existing `time_zone`.
    def method_missing(...)
      wrap_with_time_zone time.__send__(...)
    rescue NoMethodError => e
      raise e, e.message.sub(time.inspect, inspect).sub("Time", "ActiveSupport::TimeWithZone"), e.backtrace
    end

    private
      SECONDS_PER_DAY = 86400

      def incorporate_utc_offset(time, offset)
        if offset.zero?
          time
        elsif time.kind_of?(Date)
          time + Rational(offset, SECONDS_PER_DAY)
        else
          time + offset
        end
      end

      def get_period_and_ensure_valid_local_time(period)
        # we don't want a Time.local instance enforcing its own DST rules as well,
        # so transfer time values to a utc constructor if necessary
        @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
        begin
          period || @time_zone.period_for_local(@time)
        rescue ::TZInfo::PeriodNotFound
          # time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again
          @time += 1.hour
          retry
        end
      end

      def transfer_time_values_to_utc_constructor(time)
        # avoid creating another Time object if possible
        return time if time.instance_of?(::Time) && time.utc?
        ::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec + time.subsec)
      end

      def duration_of_variable_length?(obj)
        ActiveSupport::Duration === obj && obj.variable?
      end

      def wrap_with_time_zone(time)
        if time.acts_like?(:time)
          periods = time_zone.periods_for_local(time)
          self.class.new(nil, time_zone, time, periods.include?(period) ? period : nil)
        elsif time.is_a?(Range)
          wrap_with_time_zone(time.begin)..wrap_with_time_zone(time.end)
        else
          time
        end
      end
  end
end

# These prevent Psych from calling `ActiveSupport::TimeWithZone.name`
# and triggering the deprecation warning about the change in Rails 7.1.
YAML.load_tags

Defined in activesupport/lib/active_support/time_with_zone.rb line 494 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::TimeWithZone

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close