作为记录:我从Senatu Habita的Catilinam Prima的Oratio的Cicero借了头衔。
在现实生活中,我们经常处理时间间隔。牙医约会,酒店房间预订,甚至您每天的午餐时间:安排所有这些都是将时间段调整为其他多个时间段的任务。
, . , 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
— (, ).
?
, , .
!