chronologic/lib.rs
1// #![feature(test)]
2
3//! # Time constraint reasoning
4//!
5//! This crate is dedicated to reasoning about time.
6//! It deals with time constraints, propagate them and
7//! maintain an agenda of all the possible dates consistent
8//! with the user constraints.
9//!
10//! ## Time structures
11//! Several time structures (interval, sets) are provided
12//! to make easier time manipulation.
13//!
14//! This time data defines several operators for union, intersection,
15//! translation in two ways:
16//! * by using standard operators (`&` for intersection, `|` for unsion, `+/-` for translation)
17//! * by using iterator traits (see module [`iter`]) which allows time manipulation with
18//! saving memory allocation (no intermediate structures needed)
19//!
20//! ## Time constraint management
21//! The module [`graph`] deals with time constraints graph and mainly provides two structures:
22//! * [`graph::TimeGraph`]: the time constraints graph, a time constraint is defined as an interval
23//! of duration between two instants, a graph could be considered as a collection of time constraints
24//! * [`graph::TimeScheduler`]: the scheduler maintains a set of slots (one for each instant) according to
25//! its time graph
26//!
27//! Any modification of constraints are automatically propagated (see [`graph::TimeGraph`] for more
28//! informations about the propagation algorithm).
29//!
30mod wins;
31pub use wins::*;
32
33pub mod iter;
34
35mod ops;
36
37mod relns;
38pub use relns::*;
39
40pub mod graph;
41mod seq;
42
43
44use std::fmt::Debug;
45use std::ops::Neg;
46
47// Inner value to represent infinite values (negative or positive)
48const INFINITE_TIME_VALUE : i64 = i64::MAX;
49
50const SUBSEC_BITLEN: usize = 30; // more than nanosecond precision
51// could be set to 20 for microseconds precision, to 10 for millisecond
52// and set to 0 to get only second precision
53// (but we kept nanos to be compliant with std::time precision)
54
55// fractional part mask
56const SUBSEC_BITMASK: i64 = !((!0) << SUBSEC_BITLEN);
57
58// max of seconds according to fract. part precision
59const MAX_SEC: i64 = i64::MAX >> SUBSEC_BITLEN;
60
61
62/// # A unique point of a time window
63///
64/// Depending of the implementation, it could be relative to
65/// a date (e.g. [`Timestamp`]) or a duration (e.g. [`TimeValue`]).
66///
67/// All the time data are internally represented by a number of *ticks*.
68/// As a consequence, a tick is the most precision that you can get.
69///
70/// In this crate revision, the precision (i.e. the duration of one tick)
71/// is fixed and equals a little bit less that a nanosecond.
72/// It is exactly `1/2^30` seconde.
73pub trait TimePoint : Debug+Clone+Copy+Eq+Ord+Neg<Output=Self>+Sized {
74
75 /// The infinite time point (∞) which
76 /// is used to infinite time window bounds
77 const INFINITE: Self;
78
79 /// Checks if this value is finite
80 fn is_finite(&self) -> bool;
81
82 /// Checks if this value equals +∞
83 fn is_future_infinite(&self) -> bool;
84
85 /// Checks if this value equals -∞
86 fn is_past_infinite(&self) -> bool;
87
88 /// Returns a value *just after* this one
89 ///
90 /// *Just after* means here a point with exactly
91 /// one tick more; a tick represents the smallest
92 /// duration which could be represented.
93 ///
94 /// If a time point is infinite (-∞ or +∞),
95 /// the *just after* time point does not change and remains infinite.
96 fn just_after(&self) -> Self;
97
98 /// Returns a value *just before* this one
99 ///
100 /// *Just before* means here a point with exactly
101 /// one tick less; a tick represents the smallest
102 /// duration which could be represented.
103 ///
104 /// If a time point is infinite (-∞ or +∞),
105 /// the *just before* time point does not change and remains infinite.
106 fn just_before(&self) -> Self;
107}