datetime
The Python standard-library module and type that represent a date and time of day.
In more detail
datetime objects can be compared, subtracted to give a timedelta, and used as dict keys. A datetime can be naive or carry a time zone.
Examples
Python randomises datetime hashes per process, as it does for str and bytes.In this course: datetime.now(timezone.utc) reads the machine's clock, which makes any code that calls it a moving input. Passing a fixed datetime in as an argument lets a test state the exact instant and boundary it means.Related terms
- hash randomisation — Mixing a secret random value, chosen when a process starts, into string hashing so that hash values cannot be predicted from outside.
- UTC — Coordinated Universal Time, the worldwide reference time that does not change with seasons or time zones.
- frozen time — Making the current time a fixed value during a test, by passing an instant in or patching the clock.
- wall clock — The computer's real current time, which keeps moving while a program or test runs.
Taught in
- What A Hash Function Promises — Algorithms & Data Structures for Working Engineers
- Collisions In Practice And Hash Flooding — Algorithms & Data Structures for Working Engineers
- Testing Time And Randomness — Automated Testing, TDD & Quality Engineering
- Flaky Tests And How To Kill Them — Automated Testing, TDD & Quality Engineering