Skip to content

Latest commit

 

History

History
 
 

3_3_date_time

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Task 3.3: Date and time

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:

Duration measurements for code

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).

Task

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

Questions

After completing everything above, you should be able to answer (and understand why) the following questions:

  • How does system clock and monotonic clock differ? What are use-cases for both?
  • Why is system clock is not reliable for measuring duration? What causes its drift?
  • What is the main practical difference between chrono and time crates?
  • When hifitime crate could be useful?