Class: TickTock::Duration
- Inherits:
-
Object
- Object
- TickTock::Duration
- Defined in:
- lib/tick-tock/duration.rb
Constant Summary collapse
- MILLIS_IN_SECOND =
1000
- MILLIS_IN_MINUTE =
MILLIS_IN_SECOND * 60
- MILLIS_IN_HOUR =
MILLIS_IN_MINUTE * 60
- MILLIS_IN_DAY =
MILLIS_IN_HOUR * 24
- MILLIS_IN_WEEK =
MILLIS_IN_DAY * 7
- MILLIS_IN_YEAR =
MILLIS_IN_WEEK * 52
Instance Attribute Summary collapse
-
#raw_millis ⇒ Object
readonly
Returns the value of attribute raw_millis.
Class Method Summary collapse
- .from_pieces(millis = 0, seconds = 0, minutes = 0, hours = 0, days = 0, weeks = 0, years = 0) ⇒ Object
- .from_times(start, finish) ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #days ⇒ Object
- #hours ⇒ Object
-
#initialize(millis = 0) ⇒ Duration
constructor
A new instance of Duration.
- #inspect ⇒ Object
- #millis ⇒ Object
- #minutes ⇒ Object
- #seconds ⇒ Object
- #to_s ⇒ Object
- #weeks ⇒ Object
- #years ⇒ Object
Constructor Details
Instance Attribute Details
#raw_millis ⇒ Object (readonly)
Returns the value of attribute raw_millis.
12 13 14 |
# File 'lib/tick-tock/duration.rb', line 12 def raw_millis @raw_millis end |
Class Method Details
.from_pieces(millis = 0, seconds = 0, minutes = 0, hours = 0, days = 0, weeks = 0, years = 0) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/tick-tock/duration.rb', line 18 def self.from_pieces(millis=0, seconds=0, minutes=0, hours=0, days=0, weeks=0, years=0) Duration.new(millis + seconds * MILLIS_IN_SECOND + minutes * MILLIS_IN_MINUTE + hours * MILLIS_IN_HOUR + days * MILLIS_IN_DAY + weeks * MILLIS_IN_WEEK + years * MILLIS_IN_YEAR) end |
Instance Method Details
#+(other) ⇒ Object
33 34 35 |
# File 'lib/tick-tock/duration.rb', line 33 def +(other) Duration.new(raw_millis + other.raw_millis) end |
#-(other) ⇒ Object
37 38 39 |
# File 'lib/tick-tock/duration.rb', line 37 def -(other) Duration.new(raw_millis - other.raw_millis) end |
#days ⇒ Object
49 50 51 |
# File 'lib/tick-tock/duration.rb', line 49 def days (raw_millis - years_in_millis - weeks_in_millis) / MILLIS_IN_DAY end |
#hours ⇒ Object
53 54 55 |
# File 'lib/tick-tock/duration.rb', line 53 def hours (raw_millis - years_in_millis - weeks_in_millis - days_in_millis) / MILLIS_IN_HOUR end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/tick-tock/duration.rb', line 73 def inspect to_s end |
#millis ⇒ Object
65 66 67 |
# File 'lib/tick-tock/duration.rb', line 65 def millis raw_millis - years_in_millis - weeks_in_millis - days_in_millis - hours_in_millis - minutes_in_millis - seconds_in_millis end |
#minutes ⇒ Object
57 58 59 |
# File 'lib/tick-tock/duration.rb', line 57 def minutes (raw_millis - years_in_millis - weeks_in_millis - days_in_millis - hours_in_millis) / MILLIS_IN_MINUTE end |
#seconds ⇒ Object
61 62 63 |
# File 'lib/tick-tock/duration.rb', line 61 def seconds (raw_millis - years_in_millis - weeks_in_millis - days_in_millis - hours_in_millis - minutes_in_millis) / MILLIS_IN_SECOND end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/tick-tock/duration.rb', line 69 def to_s @formatter.to_s end |
#weeks ⇒ Object
45 46 47 |
# File 'lib/tick-tock/duration.rb', line 45 def weeks (raw_millis - years_in_millis) / MILLIS_IN_WEEK end |
#years ⇒ Object
41 42 43 |
# File 'lib/tick-tock/duration.rb', line 41 def years raw_millis / MILLIS_IN_YEAR end |