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.
54 55 56 57 58 |
# File 'lib/biz/day_time.rb', line 54 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.
60 61 62 |
# File 'lib/biz/day_time.rb', line 60 def day_second @day_second end |
Class Method Details
.endnight ⇒ Object
48 49 50 |
# File 'lib/biz/day_time.rb', line 48 def endnight ENDNIGHT end |
.from_hour(hour) ⇒ Object
30 31 32 |
# File 'lib/biz/day_time.rb', line 30 def from_hour(hour) new(hour * Time.hour_seconds) end |
.from_minute(minute) ⇒ Object
26 27 28 |
# File 'lib/biz/day_time.rb', line 26 def from_minute(minute) new(minute * Time.minute_seconds) end |
.from_time(time) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/biz/day_time.rb', line 18 def from_time(time) new( time.hour * Time.hour_seconds + time.min * Time.minute_seconds + time.sec ) end |
.from_timestamp(timestamp) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/biz/day_time.rb', line 34 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
44 45 46 |
# File 'lib/biz/day_time.rb', line 44 def midnight MIDNIGHT end |
Instance Method Details
#day_minute ⇒ Object
74 75 76 |
# File 'lib/biz/day_time.rb', line 74 def day_minute hour * Time.hour_minutes + minute end |
#for_dst ⇒ Object
78 79 80 |
# File 'lib/biz/day_time.rb', line 78 def for_dst self.class.new((day_second + Time.hour_seconds) % Time.day_seconds) end |
#hour ⇒ Object
62 63 64 |
# File 'lib/biz/day_time.rb', line 62 def hour day_second / Time.hour_seconds end |
#minute ⇒ Object
66 67 68 |
# File 'lib/biz/day_time.rb', line 66 def minute day_second % Time.hour_seconds / Time.minute_seconds end |
#second ⇒ Object
70 71 72 |
# File 'lib/biz/day_time.rb', line 70 def second day_second % Time.minute_seconds end |
#timestamp ⇒ Object
82 83 84 |
# File 'lib/biz/day_time.rb', line 82 def format(Timestamp::FORMAT, hour, minute) end |