Class: Biz::DayTime
Instance Attribute Summary collapse
-
#day_second ⇒ Object
readonly
Returns the value of attribute day_second.
Class Method Summary collapse
- .endnight ⇒ Object
- .from_hour(hour) ⇒ Object
- .from_minute(minute) ⇒ Object
- .from_time(time) ⇒ Object
- .from_timestamp(timestamp) ⇒ Object
- .midnight ⇒ Object
Instance Method Summary collapse
- #day_minute ⇒ Object
- #for_dst ⇒ Object
- #hour ⇒ Object
-
#initialize(day_second) ⇒ DayTime
constructor
A new instance of DayTime.
- #minute ⇒ Object
- #second ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(day_second) ⇒ DayTime
Returns a new instance of DayTime.
53 54 55 56 57 |
# File 'lib/biz/day_time.rb', line 53 def initialize(day_second) @day_second = Integer(day_second) fail ArgumentError, 'second not within a day' unless valid_second? end |
Instance Attribute Details
#day_second ⇒ Object (readonly)
Returns the value of attribute day_second.
59 60 61 |
# File 'lib/biz/day_time.rb', line 59 def day_second @day_second end |
Class Method Details
.endnight ⇒ Object
47 48 49 |
# File 'lib/biz/day_time.rb', line 47 def endnight ENDNIGHT end |
.from_hour(hour) ⇒ Object
29 30 31 |
# File 'lib/biz/day_time.rb', line 29 def from_hour(hour) new(hour * Time.hour_seconds) end |
.from_minute(minute) ⇒ Object
25 26 27 |
# File 'lib/biz/day_time.rb', line 25 def from_minute(minute) new(minute * Time.minute_seconds) end |
.from_time(time) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/biz/day_time.rb', line 17 def from_time(time) new( time.hour * Time.hour_seconds + time.min * Time.minute_seconds + time.sec ) end |
.from_timestamp(timestamp) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/biz/day_time.rb', line 33 def () .match(Timestamp::PATTERN) { |match| new( match[:hour].to_i * Time.hour_seconds + match[:minute].to_i * Time.minute_seconds + match[:second].to_i ) } end |
.midnight ⇒ Object
43 44 45 |
# File 'lib/biz/day_time.rb', line 43 def midnight MIDNIGHT end |
Instance Method Details
#day_minute ⇒ Object
73 74 75 |
# File 'lib/biz/day_time.rb', line 73 def day_minute hour * Time.hour_minutes + minute end |
#for_dst ⇒ Object
77 78 79 |
# File 'lib/biz/day_time.rb', line 77 def for_dst self.class.new((day_second + Time.hour_seconds) % Time.day_seconds) end |
#hour ⇒ Object
61 62 63 |
# File 'lib/biz/day_time.rb', line 61 def hour day_second / Time.hour_seconds end |
#minute ⇒ Object
65 66 67 |
# File 'lib/biz/day_time.rb', line 65 def minute day_second % Time.hour_seconds / Time.minute_seconds end |
#second ⇒ Object
69 70 71 |
# File 'lib/biz/day_time.rb', line 69 def second day_second % Time.minute_seconds end |
#timestamp ⇒ Object
81 82 83 |
# File 'lib/biz/day_time.rb', line 81 def format(Timestamp::FORMAT, hour, minute) end |