, . , , , . .
:
. 15- ( , ). .
:
- 0xF = 0x1111 = > .
- 0xC = 0x1100 = > .
24 . , , . 24 .
, 00:00 23:59 business_hours['monday'] = 0x0000 0000 FFFF 0FFF F000 0000
_, .
:
event_a = 0x0000 0000 00F0 0000 0000 0000
event_b = 0x0000 0000 0000 07F8 0000 0000
busy_hours = event_a & event_b
busy_hours business_hours :
available_hours = business_hours (busy_hours ^ 0xFFFF FFFF FFFF FFFF FFFF FFFF)
xor (^) essentialy busy_hours not_busy_hours. Anding (&) not_busy_hours business_hours .
.
all_available_hours = person_a_available_hours & person_b_available_hours & person_c_available_hours
, . - :
, , . , 0.
, :
0x1 = > 15 , 0x3 = > , 0x7 = > 45 , 0xF = > ,... 0xFF = > 2 ..
, :
acceptable_times =[]
(0 .. 24 * 4 - (
acceptable_times.unshift(time_slot_in_hex) if available_hours & (time_slot_in_hex << i) == time_slot_in_hex << i
end
. . , .
24 * 4 24 , 4 .
- (#of time chunks in time slot) 1 15 , . (Math.log(time_slot_in_hex)/Math.log(2)).floor + 1
, , (15 ) . , . , , _ .
, , , , , , .
, (..: [800..1200, 1300..1700]) . - . , , , .. , , - , .