NHSE/NHSE.Core/Structures/Misc/GSaveDate.cs
2026-01-13 16:02:58 -06:00

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);
}