Rust has a simple std::time
module which contains very basic primitives for time measurements. To operate with dates, time zones, epochs, and other related stuff, the time
and chrono
crates are used in Rust ecosystem.
The main difference between them (except the API, ergonomics and maintaining activity) is that chrono
crate parametrizes time zone in types, while time
crate handles it in runtime. In practice, we recommend to use time
crate (unless chrono
better suits your needs), as it's much actively maintained and evolved.
If you hit limitations of time
and chrono
crates regarding their accuracy (like swallowing leap seconds) or supported formats/standards (like TAI), consider using the hifitime
crate, representing a scientifically accurate and formally verified date and time library.
For better understanding and familiarity, read through the following documentation:
- Official
std::time
docs - Official
time
crate docs - Official
chrono
crate docs - Official
hifitime
crate docs
Beware, that to measure duration of some operation, you should not use time
crate primitives or an std::time::SystemTime
, but only an std::time::Instant
instead, as it provides monotonic clock measurement (otherwise, your time measurement may be inconsistent due to system clock drift).
Estimated time: 1 day
Provide implementations for User::age()
and User::is_adult()
methods in this task's crate.
Prove your implementation correctness with additional tests. For tests reproducibility consider that "now time" is the date specified in the NOW
constant.
💡 The structure needs to be modified
After completing everything above, you should be able to answer (and understand why) the following questions: