class ZTimeLabel
For ScheduledResource
protocol. This is a base UseBlock class for ZTimeHeader
use-block subclasses. These are timezone-aware time headers (rows) and labels (use-blocks). The timezone is specified by the last component of the resource id (rid). Eg, for ‘-8’ the timezone is ActiveSupport::TimeZone.new(-8)
Constants
- TZ_INT_MAP
Attributes
Public Class Methods
# File lib/z_time_label.rb, line 85 def self.end_for_start(t) t + 1 end
# File lib/z_time_label.rb, line 86 def self.floor(t) t end
(ScheduledResource
protocol) Returns a hash where each key is an rid
and the value is an array of ZTimeLabels (use blocks) in the interval t1...t2
, ordered by starttime
.
What in means depends on inc. If inc(remental) is nil/false, client is building the interval from scratch. If “hi”, it is an addition to an existing interval on the high side. Similarly for “lo”. This is to avoid re-transmitting blocks that span the current time boundaries on the client.
Here the resource is a ZTimeHeader
and the use-blocks are ZTimeLabels.
Parameters¶ ↑
-
rids
- A list of schedules resource ids (strings). -
t1
- Start time. -
t2
- End time. -
inc
- One of nil, “lo”, “hi” (See above).
Returns¶ ↑
-
Hash
- Each key is arid
such as Hour0
and the value is an array of Timelabels in the interval, ordered by starttime
.
# File lib/z_time_label.rb, line 40 def self.get_all_blocks(ids, t1, t2, inc) h = {} ids.each{|id| h[id] = get_timeblocks(id, t1, t2, inc)} h end
# File lib/z_time_label.rb, line 47 def self.get_timeblocks(id, t1, t2, inc) tz = tz_from_rid( id ) t1 = floor( tz.at(t1) ) t1 = end_for_start(t1) if inc == 'hi' t2 = tz.at(t2) t2 = floor( t2 ) - 1 if inc == 'lo' enum_for( :time_blocks_starting_through, t1, t2 ).to_a end
Parameters are TimeWithZone or similar
# File lib/z_time_label.rb, line 12 def initialize( starttime, endtime ) @starttime, @endtime = starttime, endtime end
# File lib/z_time_label.rb, line 81 def self.offset_from_rid( rid ) (rid.split('_').last || '').to_i end
# File lib/z_time_label.rb, line 60 def self.time_blocks_starting_through( starttime, limit ) while starttime <= limit do # Hmm... I would have guessed '<' over '<='... endtime = end_for_start starttime yield new( starttime, endtime ) starttime = endtime end end
# File lib/z_time_label.rb, line 76 def self.tz_from_rid( rid ) # ActiveSupport::TimeZone.new offset_from_rid(rid) TZ_INT_MAP[ offset_from_rid(rid) ] || TZ_INT_MAP[-8] end