-
Notifications
You must be signed in to change notification settings - Fork 0
/
loghours.dart
43 lines (35 loc) · 1.09 KB
/
loghours.dart
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
import 'dart:io';
import 'dart:core';
String startInput, endInput;
bool loggingStarted = false;
DateTime startTime, endTime;
void main() {
while (startInput != "code") {
stdout.writeln("Type 'code' to start logging.");
startInput = stdin.readLineSync();
}
if (startInput == "code") {
loggingStarted = true;
startTime = new DateTime.now();
stdout.writeln("Logging started! Type 'mate' when you stop");
endLogging();
}
}
String getUsedTime(DateTime startTime, DateTime endTime) {
Duration duration = endTime.difference(startTime);
String usedTimeString = duration.toString();
return usedTimeString;
}
void endLogging() {
while (endInput != "mate") {
stdout.writeln("Type 'mate' to end logging.");
endInput = stdin.readLineSync();
}
if (endInput == "mate" && loggingStarted) {
loggingStarted = false;
endTime = new DateTime.now();
var usedTime = getUsedTime(startTime, endTime);
String usedTimeTrimmed = usedTime.substring(0, 7);
stdout.writeln("Logging has end. You used $usedTimeTrimmed Thank you for logging the time!");
}
}