@@ -29,6 +29,7 @@ Authors: $(HTTP jmdavisprog.com, Jonathan M Davis), Ilya Yaroshenko (boost-like
2929+/
3030module mir.date ;
3131
32+ import mir.timestamp: Timestamp;
3233import mir.serde: serdeProxy, serdeScoped;
3334import std.range.primitives : isOutputRange;
3435import std.traits : isSomeChar, Unqual;
@@ -243,12 +244,55 @@ enum DayOfWeek
243244}
244245
245246// /
247+ @serdeProxy! Timestamp
246248struct YearMonthDay
247249{
248250 short year = 1 ;
249251 Month month = Month.jan;
250252 ubyte day = 1 ;
251253
254+ // /
255+ Timestamp timestamp () @safe pure nothrow @nogc @property
256+ {
257+ return Timestamp (year, cast (ubyte )month, day);
258+ }
259+
260+ // /
261+ alias opCast (T : Timestamp) = timestamp;
262+
263+ // /
264+ version (mir_test)
265+ unittest
266+ {
267+ import mir.timestamp;
268+ auto timestamp = cast (Timestamp) YearMonthDay(2020 , Month.may, 12 );
269+ }
270+
271+ // /
272+ this (short year, Month month, ubyte day) @safe pure nothrow @nogc
273+ {
274+ this .year = year;
275+ this .month = month;
276+ this .day = day;
277+ }
278+
279+ // /
280+ this (Date date) @safe pure nothrow @nogc
281+ {
282+ this = date.yearMonthDay;
283+ }
284+
285+ version (D_Exceptions)
286+ // /
287+ this (Timestamp timestamp) @safe pure nothrow @nogc
288+ {
289+ if (timestamp.precision != Timestamp.Precision.day)
290+ {
291+ static immutable exc = new Exception (" YearMonthDay: invalid timestamp precision" );
292+ }
293+ with (timestamp) this (year, cast (Month)month, day);
294+ }
295+
252296 // Shares documentation with "years" version.
253297 @safe pure nothrow @nogc
254298 ref YearMonthDay add (string units)(long months, AllowDayOverflow allowOverflow = AllowDayOverflow.yes)
@@ -410,8 +454,7 @@ struct YearMonthDay
410454 +/
411455extern (C++ , " boost" , " gregorian" )
412456extern (C++ , class)
413- @serdeScoped
414- @serdeProxy! (const (char )[])
457+ @serdeProxy! YearMonthDay
415458struct date
416459{
417460extern (D ):
@@ -507,6 +550,22 @@ public:
507550 return ret;
508551 }
509552
553+ // /
554+ Timestamp timestamp () @safe pure nothrow @nogc @property
555+ {
556+ return yearMonthDay.timestamp;
557+ }
558+
559+ version (D_Exceptions)
560+ // /
561+ this (Timestamp timestamp) @safe pure @nogc
562+ {
563+ if (timestamp.precision != Timestamp.Precision.day)
564+ {
565+ static immutable exc = new Exception (" Date: invalid timestamp precision" );
566+ }
567+ }
568+
510569 version (D_Exceptions)
511570 // /
512571 this (scope const (char )[] str) @safe pure @nogc
0 commit comments