Skip to content

Commit 60f6519

Browse files
committed
Code formatting and break classes into their own files. .NET6 file scoped namespaces
1 parent 1d145d5 commit 60f6519

3 files changed

Lines changed: 373 additions & 365 deletions

File tree

Duration.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
3+
namespace Caffeinated;
4+
5+
public class Duration : IComparable {
6+
public int Minutes { get; set; }
7+
public string Description {
8+
get {
9+
return Duration.ToDescription(Minutes);
10+
}
11+
}
12+
13+
public static string ToDescription(int time) {
14+
if (time == 0) {
15+
return "Indefinitely";
16+
}
17+
18+
string returnDescription = "";
19+
20+
if (time >= 60) {
21+
int hours = time / 60;
22+
if (hours == 1) {
23+
returnDescription = "1 hr ";
24+
}
25+
else {
26+
returnDescription = string.Format("{0} hrs ", hours);
27+
}
28+
}
29+
int mins = time % 60;
30+
if (mins == 1) {
31+
returnDescription += string.Format("{0} min", mins);
32+
}
33+
if (mins > 1) {
34+
returnDescription += string.Format("{0} mins", mins);
35+
}
36+
37+
return returnDescription;
38+
}
39+
40+
public int CompareTo(object? obj) {
41+
if (obj == null) {
42+
return 1;
43+
}
44+
45+
if (obj is Duration otherDuration) {
46+
if (otherDuration.Minutes > Minutes) {
47+
return 1;
48+
}
49+
50+
if (otherDuration.Minutes < Minutes) {
51+
return -1;
52+
}
53+
54+
return 0;
55+
}
56+
else {
57+
return 1;
58+
}
59+
}
60+
}

NativeMethods.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace Caffeinated;
4+
5+
internal static class NativeMethods {
6+
[DllImport("kernel32.dll")]
7+
public static extern uint SetThreadExecutionState(uint esFlags);
8+
public const uint ES_CONTINUOUS = 0x80000000;
9+
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
10+
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
11+
}

0 commit comments

Comments
 (0)