Sha256: 7b6af49d3f2b9c238de8eec45121226e9c2d48ab569a61a22209dd9340d7c58a

Contents?: true

Size: 614 Bytes

Versions: 1

Compression:

Stored size: 614 Bytes

Contents

# -*- coding: utf-8 -*-

require "time"

# Time extensions

class Time

  # @return [Time] a random time
  #
  # This calls `DateTime.rand`.
  #
  # The default range is +/- 10000 days from now,
  # which is the same as `Date.rand` and `DateTime.rand`.
  #
  # @example
  #
  #   Time.rand
  #   => "2014-12-31 12:59:59Z" 
  #
  # @example with a range
  #
  #   now = Time.now
  #   range = (now - 10000)..(now + 10000)
  #   Time.rand(range)
  #
  # @param [Range<Time..Time>] A range of potential times, or nil for the default range.
  #
  def self.rand(range = nil)
    DateTime.rand(range).to_time
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sixarm_ruby_date_time_rand-2.0.2 lib/sixarm_ruby_date_time_rand/time.rb