forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathTime.cs
84 lines (68 loc) · 1.81 KB
/
Time.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
namespace WDE.MpqReader.DBC;
public struct Time : IComparable<Time>
{
private int minutes;
public Time(int hours, int minutes)
{
this.minutes = hours * 60 + minutes;
}
public int Hour => minutes / 60;
public int Minute => minutes % 60;
public int TotalMinutes => minutes;
public int HalfHourInMinutes => (int)Math.Round((minutes / 30.0f)) * 30;
public bool Equals(Time other)
{
return minutes == other.minutes;
}
public override bool Equals(object? obj)
{
return obj is Time other && Equals(other);
}
public override int GetHashCode()
{
return minutes;
}
public int CompareTo(Time other)
{
return minutes.CompareTo(other.minutes);
}
public static bool operator <(Time left, Time right)
{
return left.CompareTo(right) < 0;
}
public static bool operator >(Time left, Time right)
{
return left.CompareTo(right) > 0;
}
public static bool operator <=(Time left, Time right)
{
return left.CompareTo(right) <= 0;
}
public static bool operator >=(Time left, Time right)
{
return left.CompareTo(right) >= 0;
}
public static bool operator ==(Time left, Time right)
{
return left.Equals(right);
}
public static bool operator !=(Time left, Time right)
{
return !left.Equals(right);
}
public static Time FromHalfMinutes(int minutes)
{
return new Time(0, minutes / 2);
}
public static Time FromMinutes(int minutes)
{
return new Time(0, minutes);
}
public static Time operator -(Time left, Time right)
{
var diff = left.minutes - right.minutes;
if (diff < 0)
diff += 1440;
return new Time(0, diff);
}
}