using System; namespace AsbCloudApp.Data { /// /// DTO времени /// public class TimeDto : IComparable { private int hour = 0; private int minute = 0; private int second = 0; /// /// час /// public int Hour { get => hour; set { if (value > 23 || value < 0) throw new ArgumentOutOfRangeException(nameof(Hour), "hour should be in [0; 23]"); hour = value; } } /// /// минута /// public int Minute { get => minute; set { if (value > 59 || value < 0) throw new ArgumentOutOfRangeException(nameof(minute), "minute should be in [0; 59]"); minute = value; } } /// /// секунда /// public int Second { get => second; set { if (value > 59 || value < 0) throw new ArgumentOutOfRangeException(nameof(second), "second should be in [0; 59]"); second = value; } } /// /// Кол-во секунд с начала суток /// public int TotalSeconds => (Hour * 60 + minute) * 60 + second; /// public TimeDto() { } /// public TimeDto(int hour = 0, int minute = 0, int second = 0) { this.hour = hour; this.minute = minute; this.second = second; } /// public TimeDto(TimeOnly time) { hour = time.Hour; minute = time.Minute; second = time.Second; } /// public TimeDto(DateTime fullDate) { hour = fullDate.Hour; minute = fullDate.Minute; second = fullDate.Second; } /// /// Makes System.TimeOnly /// /// System.TimeOnly public TimeOnly MakeTimeOnly() => new(Hour, Minute, Second); /// public override string ToString() { var str = $"{Hour:00}:{Minute:00}:{Second:00}"; return str; } /// public static bool operator ==(TimeDto a, TimeDto b) => a?.TotalSeconds == b?.TotalSeconds; /// public static bool operator !=(TimeDto a, TimeDto b) => !(a == b); /// public static bool operator <=(TimeDto a, TimeDto b) => a.TotalSeconds <= b.TotalSeconds; /// public static bool operator >=(TimeDto a, TimeDto b) => a.TotalSeconds >= b.TotalSeconds; /// public static bool operator <(TimeDto a, TimeDto b) => a.TotalSeconds < b.TotalSeconds; /// public static bool operator >(TimeDto a, TimeDto b) => a.TotalSeconds > b.TotalSeconds; /// public int CompareTo(TimeDto other) => TotalSeconds - other.TotalSeconds; /// public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return true; } if (obj is null) { return false; } if (obj is TimeDto objTime) { return objTime == this; } return false; } /// public override int GetHashCode() { return base.GetHashCode(); } } }