|
| 1 | +partial struct SYSTEMTIME |
| 2 | + : IEquatable<SYSTEMTIME> |
| 3 | +{ |
| 4 | + public bool Equals(SYSTEMTIME other) |
| 5 | + { |
| 6 | + return this.wYear == other.wYear && |
| 7 | + this.wMonth == other.wMonth && |
| 8 | + this.wDayOfWeek == other.wDayOfWeek && |
| 9 | + this.wDay == other.wDay && |
| 10 | + this.wHour == other.wHour && |
| 11 | + this.wMinute == other.wMinute && |
| 12 | + this.wSecond == other.wSecond && |
| 13 | + this.wMilliseconds == other.wMilliseconds; |
| 14 | + } |
| 15 | + |
| 16 | + public override bool Equals(object obj) => obj is SYSTEMTIME other && this.Equals(other); |
| 17 | + public override int GetHashCode() => (this.wYear, this.wMonth, this.wDayOfWeek, this.wDay, this.wHour, this.wMinute, this.wSecond, this.wMilliseconds).GetHashCode(); |
| 18 | + |
| 19 | + public static bool operator ==(SYSTEMTIME d1, SYSTEMTIME d2) |
| 20 | + { |
| 21 | + return d1.wYear == d2.wYear && |
| 22 | + d1.wMonth == d2.wMonth && |
| 23 | + d1.wDayOfWeek == d2.wDayOfWeek && |
| 24 | + d1.wDay == d2.wDay && |
| 25 | + d1.wHour == d2.wHour && |
| 26 | + d1.wMinute == d2.wMinute && |
| 27 | + d1.wSecond == d2.wSecond && |
| 28 | + d1.wMilliseconds == d2.wMilliseconds; |
| 29 | + } |
| 30 | + |
| 31 | + public static bool operator !=(SYSTEMTIME d1, SYSTEMTIME d2) |
| 32 | + { |
| 33 | + return d1.wYear != d2.wYear && |
| 34 | + d1.wMonth != d2.wMonth && |
| 35 | + d1.wDayOfWeek != d2.wDayOfWeek && |
| 36 | + d1.wDay != d2.wDay && |
| 37 | + d1.wHour != d2.wHour && |
| 38 | + d1.wMinute != d2.wMinute && |
| 39 | + d1.wSecond != d2.wSecond && |
| 40 | + d1.wMilliseconds != d2.wMilliseconds; |
| 41 | + } |
| 42 | + |
| 43 | + public static implicit operator global::System.DateTime(SYSTEMTIME sysTime) |
| 44 | + { |
| 45 | + if (sysTime == default(SYSTEMTIME) || sysTime.wYear <= 0 || sysTime.wMonth <= 0 || sysTime.wDay <= 0) |
| 46 | + { |
| 47 | + return default; |
| 48 | + } |
| 49 | + |
| 50 | + // DateTime gets DayOfWeek automatically |
| 51 | + return new global::System.DateTime(sysTime.wYear, |
| 52 | + sysTime.wMonth, sysTime.wDay, sysTime.wHour, |
| 53 | + sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds); |
| 54 | + } |
| 55 | + |
| 56 | + public static implicit operator SYSTEMTIME(global::System.DateTime time) |
| 57 | + { |
| 58 | + if (time == default) |
| 59 | + { |
| 60 | + return default; |
| 61 | + } |
| 62 | + |
| 63 | + return new SYSTEMTIME |
| 64 | + { |
| 65 | + wYear = checked((ushort)time.Year), |
| 66 | + wMonth = checked((ushort)time.Month), |
| 67 | + wDayOfWeek = checked((ushort)time.DayOfWeek), |
| 68 | + wDay = checked((ushort)time.Day), |
| 69 | + wHour = checked((ushort)time.Hour), |
| 70 | + wMinute = checked((ushort)time.Minute), |
| 71 | + wSecond = checked((ushort)time.Second), |
| 72 | + wMilliseconds = checked((ushort)time.Millisecond) |
| 73 | + }; |
| 74 | + } |
| 75 | +} |
0 commit comments