Class: Chronic::Time
- Inherits:
-
Object
- Object
- Chronic::Time
- Defined in:
- lib/chronic/time.rb
Constant Summary collapse
- HOUR_SECONDS =
60 * 60
3600
- MINUTE_SECONDS =
60
- SECOND_SECONDS =
haha, awesome
1
- SUBSECOND_SECONDS =
0.001
Class Method Summary collapse
-
.could_be_hour?(hour) ⇒ Boolean
Checks if given number could be hour.
-
.could_be_minute?(minute) ⇒ Boolean
Checks if given number could be minute.
-
.could_be_second?(second) ⇒ Boolean
Checks if given number could be second.
-
.could_be_subsecond?(subsecond) ⇒ Boolean
Checks if given number could be subsecond.
-
.normalize_offset(offset) ⇒ Object
normalize offset in seconds to offset as string +mm:ss or -mm:ss.
Class Method Details
.could_be_hour?(hour) ⇒ Boolean
Checks if given number could be hour
9 10 11 |
# File 'lib/chronic/time.rb', line 9 def self.could_be_hour?(hour) hour >= 0 && hour <= 24 end |
.could_be_minute?(minute) ⇒ Boolean
Checks if given number could be minute
14 15 16 |
# File 'lib/chronic/time.rb', line 14 def self.could_be_minute?(minute) minute >= 0 && minute <= 60 end |
.could_be_second?(second) ⇒ Boolean
Checks if given number could be second
19 20 21 |
# File 'lib/chronic/time.rb', line 19 def self.could_be_second?(second) second >= 0 && second <= 60 end |
.could_be_subsecond?(subsecond) ⇒ Boolean
Checks if given number could be subsecond
24 25 26 |
# File 'lib/chronic/time.rb', line 24 def self.could_be_subsecond?(subsecond) subsecond >= 0 && subsecond <= 999999 end |
.normalize_offset(offset) ⇒ Object
normalize offset in seconds to offset as string +mm:ss or -mm:ss
29 30 31 32 33 34 35 36 37 |
# File 'lib/chronic/time.rb', line 29 def self.normalize_offset(offset) return offset if offset.is_a?(String) offset = Chronic.time_class.now.to_time.utc_offset unless offset # get current system's UTC offset if offset is nil sign = '+' sign = '-' if offset < 0 hours = (offset.abs / 3600).to_i.to_s.rjust(2,'0') minutes = (offset.abs % 3600).to_s.rjust(2,'0') sign + hours + minutes end |