Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/durations.rb

Overview

Durations on Integer (spec section 3.1): 5.minutes, 1.day, 2.weeks.ago, 3.days.from_now, Time.current + 90.seconds.

A duration is an Integer number of seconds (Rails answers an ActiveSupport::Duration): 5.minutes == 300 and 5.minutes.inspect is "300", so 300.ago works as 5.minutes.ago does.

month(s) and year(s) are not defined: a month has no fixed length in seconds, and an Integer cannot carry “one calendar month”. 1.month raises NoMethodError (“undefined method ‘month’ for an instance of Integer”) when it is reached, under Spinel as under CRuby: an application’s program always defines some month (ZonedTime#month), and Spinel refuses an undefined method at build only while nothing in the program defines the name (spikes/phase5/durations_month.rb). Use the calendar-aware forms on Time instead: 1.month.ago is Time.current.months_ago(1), 1.year.from_now is Time.current.years_since(1), time + 1.month is time.advance(months: 1).

Instance Method Summary collapse

Instance Method Details

#ago ⇒ Time

The Time this many seconds before Time.current, on the Clock (so it follows travel_to): 2.weeks.ago.

Returns:



77
# File 'cybertrain/durations.rb', line 77

def ago = Cybertrain::Clock.now - self

#day ⇒ Integer

1.day # => 86400.

Returns:



61
# File 'cybertrain/durations.rb', line 61

def day = self * 86_400

#days ⇒ Integer

This many days of 86,400 seconds (2.days # => 172800). For calendar days in Time.zone across a DST change, use time.advance(days: n).

Returns:



56
# File 'cybertrain/durations.rb', line 56

def days = self * 86_400

#from_now ⇒ Time

The Time this many seconds after Time.current, on the Clock: 3.days.from_now.

Returns:



83
# File 'cybertrain/durations.rb', line 83

def from_now = Cybertrain::Clock.now + self

#hour ⇒ Integer

1.hour # => 3600.

Returns:



50
# File 'cybertrain/durations.rb', line 50

def hour = self * 3600

#hours ⇒ Integer

This many hours in seconds (2.hours # => 7200).

Returns:



45
# File 'cybertrain/durations.rb', line 45

def hours = self * 3600

#minute ⇒ Integer

1.minute # => 60.

Returns:



40
# File 'cybertrain/durations.rb', line 40

def minute = self * 60

#minutes ⇒ Integer

This many minutes in seconds (5.minutes # => 300).

Returns:



35
# File 'cybertrain/durations.rb', line 35

def minutes = self * 60

#second ⇒ Integer

1.second: the Integer itself.

Returns:



30
# File 'cybertrain/durations.rb', line 30

def second = self

#seconds ⇒ Integer

This many seconds (the Integer itself).

Returns:



25
# File 'cybertrain/durations.rb', line 25

def seconds = self

#week ⇒ Integer

1.week # => 604800.

Returns:



71
# File 'cybertrain/durations.rb', line 71

def week = self * 604_800

#weeks ⇒ Integer

This many weeks in seconds (2.weeks # => 1209600).

Returns:



66
# File 'cybertrain/durations.rb', line 66

def weeks = self * 604_800