1
For design reasons, the class Datetime do. NET is not suitable for me. So I decided to create my own version:
public class HolidayDateTime
{
public readonly uint[] RangeValueDay = { 1, 31 };
public readonly uint[] RangeValueMonth = { 1, 12 };
public readonly uint[] RangeValueHour = { 0, 23 };
public readonly uint[] RangeValueMinute = { 0, 60 };
public uint Day { get; private set; }
public uint Month { get; private set; }
public uint Hour { get; private set; }
public uint Minute { get; private set; }
protected HolidayDateTime() { }
public HolidayDateTime(uint day, uint month, uint hour, uint minute)
{
Guard.IntengerRangeInvalid((int)day, (int)RangeValueDay[0], (int)RangeValueDay[1], "O dia informado é inválido");
Guard.IntengerRangeInvalid((int)month, (int)RangeValueMonth[0], (int)RangeValueMonth[1], "O mês informado é inválido");
Guard.IntengerRangeInvalid((int)hour, (int)RangeValueHour[0], (int)RangeValueHour[1], "A hora informado é inválida");
Guard.IntengerRangeInvalid((int)minute, (int)RangeValueMinute[0], (int)RangeValueMinute[1], "O minuto informado é inválido");
Day = day;
Month = month;
Hour = hour;
Minute = minute;
}
public string DateFullToString() => Day + @"/" + Month + " " + Hour + ":" + Minute;
public uint[] DateFullToArray() => new uint[] { Day, Month, Hour, Minute };
In the project I will need to make comparisons between the dates, for this I will need to overload the operators >, <, ==, >=, <= and !=
For operators == and != Boolean logic is quiet to do:
public static bool operator ==(HolidayDateTime hdaydt1, HolidayDateTime hdaydt2) => hdaydt1.Day == hdaydt2.Day && hdaydt1.Month == hdaydt2.Month && hdaydt1.Hour == hdaydt2.Hour && hdaydt1.Minute == hdaydt2.Minute;
public static bool operator !=(HolidayDateTime hdaydt1, HolidayDateTime hdaydt2) => hdaydt1.Day != hdaydt2.Day || hdaydt1.Month != hdaydt2.Month || hdaydt1.Hour != hdaydt2.Hour || hdaydt1.Minute != hdaydt2.Minute;
My difficulty lies in the operators >, <,>= and <= because the boolean combination to define whether a date is larger, smaller, larger-or-equal, smaller-or-equal is huge which would result in a hard-to-read and large code.
I would like tips for a better solution.
Actually I didn’t even try, because mentally I already predicted that it would result in a monstrous and bizarre code. Com string would even work for operators == and != but I see no possibility for other operators.
– Matheus Saraiva
Ummmm, convert to numeric, yes, can be the solution...
– Matheus Saraiva