-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #672 from elachlan/SYSTEMTIME
Add DateTime operators to SYSTEMTIME
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
partial struct SYSTEMTIME | ||
: IEquatable<SYSTEMTIME> | ||
{ | ||
public bool Equals(SYSTEMTIME other) => this.wYear == other.wYear && this.wMonth == other.wMonth && this.wDayOfWeek == other.wDayOfWeek && this.wDay == other.wDay && this.wHour == other.wHour && this.wMinute == other.wMinute && this.wSecond == other.wSecond && this.wMilliseconds == other.wMilliseconds; | ||
public override bool Equals(object obj) => obj is SYSTEMTIME other && this.Equals(other); | ||
public override int GetHashCode() => (this.wYear, this.wMonth, this.wDayOfWeek, this.wDay, this.wHour, this.wMinute, this.wSecond, this.wMilliseconds).GetHashCode(); | ||
public static bool operator ==(SYSTEMTIME d1, SYSTEMTIME d2) => d1.Equals(d2); | ||
public static bool operator !=(SYSTEMTIME d1, SYSTEMTIME d2) => !(d1 == d2); | ||
|
||
public static explicit operator global::System.DateTime(SYSTEMTIME sysTime) | ||
{ | ||
if (sysTime == default) | ||
{ | ||
return default; | ||
} | ||
|
||
return new global::System.DateTime(sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds); | ||
} | ||
|
||
public static explicit operator SYSTEMTIME(global::System.DateTime time) | ||
{ | ||
if (time == default) | ||
{ | ||
return default; | ||
} | ||
|
||
checked | ||
{ | ||
return new SYSTEMTIME | ||
{ | ||
wYear = (ushort)time.Year, | ||
wMonth = (ushort)time.Month, | ||
wDayOfWeek = (ushort)time.DayOfWeek, | ||
wDay = (ushort)time.Day, | ||
wHour = (ushort)time.Hour, | ||
wMinute = (ushort)time.Minute, | ||
wSecond = (ushort)time.Second, | ||
wMilliseconds = (ushort)time.Millisecond, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters