File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments