-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time.cs
62 lines (51 loc) · 1.71 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
namespace CourseView
{
public class Time : IComparable<Time>
{
public int Hour { get; set; }
public int Minute { get; set; }
public int Second { get; set; }
public static Time FromHourString(string timeString)
{
string[] split = Tools.DivideString(timeString, 2);
if (split.Length < 2)
return new Time();
for (int x = 0; x < split.Length; x++)
if (split[x] == "00")
split[x] = "0";
return new Time(Convert.ToInt32(split[0]), Convert.ToInt32(split[1]));
}
public static Time FromSQLString(string sqlString)
{
string[] splitStrings;
return new Time(Convert.ToInt32((splitStrings = sqlString.Split(':'))[0]),
Convert.ToInt32(splitStrings[1]),
Convert.ToInt32(splitStrings[2]));
}
public int CompareTo(Time time)
{
int[,] timeCompArray = new int[,] {
{
time.Hour, time.Minute, time.Second
},
{
this.Hour, this.Minute, this.Second
}
};
for (int x = 0; x < 3; x++)
if (timeCompArray[0, x] > timeCompArray[1, x])
return 1;
return 0;
}
public override string ToString()
{
return $"{this.Hour}:{this.Minute}:{this.Second}";
}
public Time(int hour = 0, int minute = 0, int second = 0)
{
this.Hour = hour;
this.Minute = minute;
this.Second = second;
}
}
}