mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-18 22:47:24 -05:00
29 lines
947 B
C#
29 lines
947 B
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace NHSE.Core;
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
|
[TypeConverter(typeof(ValueTypeTypeConverter))]
|
|
public struct GSaveDate
|
|
{
|
|
public const int SIZE = 4;
|
|
public override string ToString() => $"{Year:0000}-{Month:00}-{Day:00}";
|
|
|
|
public ushort Year { get; set; }
|
|
public byte Month { get; set; }
|
|
public byte Day { get; set; }
|
|
|
|
private GSaveDate(int year, int month, int day)
|
|
{
|
|
Year = (ushort) year;
|
|
Month = (byte) month;
|
|
Day = (byte) day;
|
|
}
|
|
|
|
public bool IsEmpty => Year == 0 && Month == 0 && Day == 0;
|
|
|
|
public static implicit operator GSaveDate(DateTime dt) => dt == DateTime.MinValue ? new GSaveDate() : new GSaveDate(dt.Year, dt.Month, dt.Day);
|
|
public static implicit operator DateTime(GSaveDate dt) => dt.IsEmpty ? DateTime.MinValue : new DateTime(dt.Year, dt.Month, dt.Day);
|
|
} |