99 * Use of this source code is governed by a MIT license
1010 * that can be found in the LICENSE file.
1111 *
12- * =====================================================
13- * Vix.cpp - Time Module / Date
14- * =====================================================
15- *
16- * Ergonomic date facade inspired by Node.js and Python.
17- *
18- * This type represents a calendar date (year-month-day) without time.
19- * It is designed to be:
20- * - simple to construct and parse
21- * - explicit and predictable
22- * - chrono-based
12+ * Vix.cpp
2313 */
2414
2515#ifndef VIX_TIME_DATE_HPP
3727namespace vix ::time
3828{
3929 /* *
40- * @brief Calendar date (year-month-day).
30+ * @brief Calendar date (year-month-day), without time and without timezone.
31+ *
32+ * @details
33+ * Date is a small value type representing a calendar day.
34+ * It does not store timezone data.
35+ *
36+ * Converting a Date to a @ref Timestamp is done in UTC at 00:00:00.
37+ *
38+ * This type is designed to stay friendly for beginners (simple fields, simple parsing)
39+ * while remaining useful for advanced users (chrono-based validation and conversion).
4140 *
42- * This is a lightweight value type. It does not store timezone data.
43- * All conversions to Timestamp are performed in UTC at 00:00:00.
41+ * @par Beginner example
42+ * @code
43+ * using vix::time::Date;
44+ *
45+ * Date d = Date::parse("2026-02-07");
46+ * if (!d.is_valid())
47+ * return;
48+ *
49+ * std::cout << d.to_string() << "\n";
50+ * @endcode
4451 */
4552 class Date
4653 {
4754 public:
4855 /* *
49- * @brief Construct a default date ( 1970-01-01) .
56+ * @brief Construct the default date: 1970-01-01.
5057 */
5158 constexpr Date () noexcept
5259 : year_(1970 ), month_(1 ), day_(1 )
@@ -56,27 +63,36 @@ namespace vix::time
5663 /* *
5764 * @brief Construct a date from explicit fields.
5865 *
59- * @param year Full year (e.g. 2026)
60- * @param month Month in [1..12]
61- * @param day Day in [1..31] (calendar validation is done by is_valid()).
66+ * @param year Full year (e.g. 2026).
67+ * @param month Month in [1..12] (range is checked by @ref is_valid).
68+ * @param day Day in [1..31] (calendar validation is checked by @ref is_valid).
69+ *
70+ * @note
71+ * This constructor does not validate the calendar day. Use @ref is_valid
72+ * to check validity.
6273 */
6374 constexpr Date (int year, int month, int day) noexcept
6475 : year_(year), month_(month), day_(day)
6576 {
6677 }
6778
6879 /* *
69- * @brief Current date (UTC).
80+ * @brief Current date in UTC.
81+ *
82+ * @return Today's date in UTC.
7083 *
71- * Alias of today().
84+ * @note
85+ * This is an alias of @ref today.
7286 */
7387 static Date now () noexcept
7488 {
7589 return today ();
7690 }
7791
7892 /* *
79- * @brief Current date (UTC).
93+ * @brief Current date in UTC.
94+ *
95+ * @return Today's date in UTC.
8096 */
8197 static Date today () noexcept
8298 {
@@ -92,11 +108,17 @@ namespace vix::time
92108 }
93109
94110 /* *
95- * @brief Parse date from "YYYY-MM-DD".
111+ * @brief Parse a date from "YYYY-MM-DD".
96112 *
97- * On parse failure, returns the default date (1970-01-01).
113+ * @details
114+ * On parse failure, this returns the default date (1970-01-01).
98115 *
99116 * @param s Input string view.
117+ * @return Parsed date, or default date on failure.
118+ *
119+ * @note
120+ * Parsing succeeds even if the date is not a valid calendar day.
121+ * Use @ref is_valid to validate.
100122 */
101123 static Date parse (std::string_view s) noexcept
102124 {
@@ -105,30 +127,34 @@ namespace vix::time
105127 int d = 0 ;
106128
107129 if (!vix::time::parse::parse_ymd (s, y, m, d))
108- {
109130 return Date ();
110- }
111131
112132 return Date (y, m, d);
113133 }
114134
115135 /* *
116- * @brief Return the year.
136+ * @brief Get the year component .
117137 */
118138 constexpr int year () const noexcept { return year_; }
119139
120140 /* *
121- * @brief Return the month in [1..12] (as stored).
141+ * @brief Get the month component (as stored).
142+ *
143+ * @return Month in [1..12] if valid.
122144 */
123145 constexpr int month () const noexcept { return month_; }
124146
125147 /* *
126- * @brief Return the day in [1..31] (as stored).
148+ * @brief Get the day component (as stored).
149+ *
150+ * @return Day in [1..31] if valid.
127151 */
128152 constexpr int day () const noexcept { return day_; }
129153
130154 /* *
131- * @brief Check if the date is a valid calendar day.
155+ * @brief Check if this date is a valid calendar day.
156+ *
157+ * @return True if year-month-day forms a valid date, false otherwise.
132158 */
133159 constexpr bool is_valid () const noexcept
134160 {
@@ -145,7 +171,11 @@ namespace vix::time
145171 /* *
146172 * @brief Convert this date to a UTC timestamp at 00:00:00.
147173 *
148- * If the date is invalid, returns Timestamp().
174+ * @details
175+ * If the date is invalid (@ref is_valid is false), this returns a default
176+ * constructed @ref Timestamp.
177+ *
178+ * @return UTC timestamp at midnight for this date, or default Timestamp on invalid date.
149179 */
150180 Timestamp to_timestamp_utc () const noexcept
151181 {
@@ -167,6 +197,11 @@ namespace vix::time
167197
168198 /* *
169199 * @brief Format as "YYYY-MM-DD".
200+ *
201+ * @return String representation of the date.
202+ *
203+ * @note
204+ * This does not validate the date. It prints stored fields.
170205 */
171206 std::string to_string () const
172207 {
@@ -195,7 +230,7 @@ namespace vix::time
195230 }
196231
197232 /* *
198- * @brief Strict weak ordering.
233+ * @brief Strict weak ordering (lexicographic by year, month, day) .
199234 */
200235 friend constexpr bool operator <(const Date &a, const Date &b) noexcept
201236 {
0 commit comments