forked from dmnd/Caffeinated
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDuration.cs
More file actions
60 lines (50 loc) · 1.31 KB
/
Duration.cs
File metadata and controls
60 lines (50 loc) · 1.31 KB
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
using System;
namespace Caffeinated;
public class Duration : IComparable {
public int Minutes { get; set; }
public string Description {
get {
return Duration.ToDescription(Minutes);
}
}
public static string ToDescription(int time) {
if (time == 0) {
return "Indefinitely";
}
string returnDescription = "";
if (time >= 60) {
int hours = time / 60;
if (hours == 1) {
returnDescription = "1 hr ";
}
else {
returnDescription = string.Format("{0} hrs ", hours);
}
}
int mins = time % 60;
if (mins == 1) {
returnDescription += string.Format("{0} min", mins);
}
if (mins > 1) {
returnDescription += string.Format("{0} mins", mins);
}
return returnDescription;
}
public int CompareTo(object? obj) {
if (obj == null) {
return 1;
}
if (obj is Duration otherDuration) {
if (otherDuration.Minutes > Minutes) {
return 1;
}
if (otherDuration.Minutes < Minutes) {
return -1;
}
return 0;
}
else {
return 1;
}
}
}