|
1 | | -# time |
2 | | -Provides a simple, explicit API for working with dates, times, timestamps, and durations in C++. Designed for ergonomics similar to Node.js and Python, while remaining predictable, type-safe, and aligned with modern C++ and std::chrono. |
| 1 | +# vix::time |
| 2 | + |
| 3 | +**Time and date utilities for Vix.cpp.** |
| 4 | + |
| 5 | +`vix::time` provides a simple, explicit, and predictable API for working with |
| 6 | +dates, times, timestamps, and durations in modern C++. |
| 7 | + |
| 8 | +The design is inspired by the ergonomics of Node.js and Python, while remaining |
| 9 | +fully type-safe, chrono-based, and explicit. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- 📅 **Date facade** (`Date::now()`, `Date::parse()`) |
| 16 | +- 🕒 **DateTime** with UTC support and ISO-8601 parsing |
| 17 | +- ⏱ **Timestamp** (epoch-based, nanosecond precision) |
| 18 | +- ⌛ **Duration** (strongly typed, chrono-backed) |
| 19 | +- 🧭 **System & Steady clocks** |
| 20 | +- 📦 Header-only (v1) |
| 21 | +- 🚫 No hidden allocations, no magic, no dependencies |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +`vix::time` is designed to be used as part of the Vix umbrella project. |
| 28 | + |
| 29 | +```cmake |
| 30 | +add_subdirectory(modules/time) |
| 31 | +``` |
| 32 | + |
| 33 | +Or link against the exported target: |
| 34 | + |
| 35 | +```cmake |
| 36 | +target_link_libraries(your_target PRIVATE vix::time) |
| 37 | +``` |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## Quick Example |
| 42 | + |
| 43 | +```cpp |
| 44 | +#include <vix/time/time.hpp> |
| 45 | +#include <iostream> |
| 46 | + |
| 47 | +using namespace vix::time; |
| 48 | + |
| 49 | +int main() |
| 50 | +{ |
| 51 | + Date today = Date::now(); |
| 52 | + std::cout << today.to_string() << "\n"; |
| 53 | + |
| 54 | + DateTime now = DateTime::now_utc(); |
| 55 | + std::cout << now.to_string_utc() << "\n"; |
| 56 | + |
| 57 | + Timestamp t0 = Timestamp::now(); |
| 58 | + Timestamp t1 = t0 + Duration::seconds(1); |
| 59 | + |
| 60 | + Duration delta = t1 - t0; |
| 61 | + std::cout << delta.count_seconds() << "s\n"; |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## API Overview |
| 68 | + |
| 69 | +### Date |
| 70 | + |
| 71 | +```cpp |
| 72 | +Date::now(); |
| 73 | +Date::today(); |
| 74 | +Date::parse("YYYY-MM-DD"); |
| 75 | +``` |
| 76 | +
|
| 77 | +Represents a calendar date without time. |
| 78 | +
|
| 79 | +### DateTime |
| 80 | +
|
| 81 | +```cpp |
| 82 | +DateTime::now_utc(); |
| 83 | +DateTime::parse("YYYY-MM-DDTHH:MM:SSZ"); |
| 84 | +``` |
| 85 | + |
| 86 | +Represents a full date + time in UTC. |
| 87 | + |
| 88 | +### Timestamp |
| 89 | + |
| 90 | +```cpp |
| 91 | +Timestamp::now(); |
| 92 | +Timestamp::from_seconds(1700000000); |
| 93 | +``` |
| 94 | +
|
| 95 | +Absolute point in time (nanoseconds since Unix epoch). |
| 96 | +
|
| 97 | +### Duration |
| 98 | +
|
| 99 | +```cpp |
| 100 | +Duration::seconds(5); |
| 101 | +Duration::milliseconds(250); |
| 102 | +``` |
| 103 | + |
| 104 | +Strongly typed time spans. |
| 105 | + |
| 106 | +### Clocks |
| 107 | + |
| 108 | +```cpp |
| 109 | +SystemClock::now(); // wall time (Timestamp) |
| 110 | +SteadyClock::now_chrono(); // monotonic clock |
| 111 | +SteadyClock::since(start); // elapsed Duration |
| 112 | +``` |
| 113 | +
|
| 114 | +--- |
| 115 | +
|
| 116 | +## Design Principles |
| 117 | +
|
| 118 | +- Explicit over implicit |
| 119 | +- Strong types instead of raw integers |
| 120 | +- Predictable behavior |
| 121 | +- Minimal surface API |
| 122 | +- No hidden global state |
| 123 | +
|
| 124 | +`vix::time` is intended to be a foundational module used by: |
| 125 | +
|
| 126 | +- sync |
| 127 | +- cache |
| 128 | +- WAL |
| 129 | +- retry / timeout logic |
| 130 | +- scheduling |
| 131 | +
|
| 132 | +--- |
| 133 | +
|
| 134 | +## Status |
| 135 | +
|
| 136 | +- **Version**: v0.1.0 |
| 137 | +- **Mode**: Header-only |
| 138 | +- **C++ Standard**: C++20 |
| 139 | +- **Stability**: Experimental (API subject to refinement) |
| 140 | +
|
| 141 | +--- |
| 142 | +
|
| 143 | +## License |
| 144 | +
|
| 145 | +MIT License |
| 146 | +Copyright © 2026 Gaspard Kirira |
0 commit comments