For the record: I borrowed the title from Cicero, in Oratio in Catilinam Prima in Senatu Habita .
In real life, we often deal with time intervals. Dentist appointments, hotel room reservations, even your daily lunch break: scheduling all of this is the task of adjusting the time slot to a number of other time slots.
, . , 1 . . . , โ , โ , , , โ .
, . , . , ?
, . , , .
, Tempus
!
, โ Slot
. : , from
to
, DateTime
. Slots
, AVLTree
. , ( ) . , , .
Slots.add/2
โ , . , . Slots.merge/2
. , , , , .
Slot
: ( ), , . .
Tempus
, . , ; , , , , , .
:
slots =
[
Tempus.Slot.wrap(~D|2020-08-07|), # whole day
%Tempus.Slot{
from: ~U|2020-08-08 01:01:00Z|, # one minute
to: ~U|2020-08-08 01:02:00Z|
},
%Tempus.Slot{
from: ~U|2020-08-08 01:03:00Z|, # one minute
to: ~U|2020-08-08 01:04:00Z|
}
]
|> Enum.into(%Tempus.Slots{})
0
, , .
Tempus.add(slots, ~U|2020-08-08 01:01:30Z|, 0, :second)
#โ ~U[2020-08-08 01:02:00Z]
70 , โ ~U[2020-08-08 01:00:55Z]
โ DateTime
(5sec + + 60sec + + 5sec
):
Tempus.add(slots, ~U|2020-08-08 01:00:55Z|, 70, :second)
#โ ~U[2020-08-08 01:04:05Z]
. , .
Slots.merge/2
Stream
. , . , , , , , .
, Slots
/ Slot
โ (, ).
?
, , .
!