summaryrefslogtreecommitdiff
path: root/lib/shift.dart
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-08-16 15:14:43 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2022-08-16 15:14:43 +0200
commit9144664c98824924e3d7668557a4455693bcf7f6 (patch)
tree5427daae2a5aa20a99809da44d11e33d0fe800a0 /lib/shift.dart
parent00bf8823311c067f5b0e9a785a5048e6bd8ad122 (diff)
saving and reading
Diffstat (limited to 'lib/shift.dart')
-rw-r--r--lib/shift.dart29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/shift.dart b/lib/shift.dart
index 382b39f..143fe58 100644
--- a/lib/shift.dart
+++ b/lib/shift.dart
@@ -16,10 +16,23 @@ class Shift {
Shift({this.end = null, required this.start, required this.type});
+ Shift.fromJson(Map<String, dynamic> json)
+ : start = DateTime.parse(json['start']),
+ end = json['end'] == null ? null : DateTime.tryParse(json['end']),
+ type = ShiftType.values.firstWhere((e) => e.toString() == json['type']),
+ isActive = json['isActive'] == 'true';
+
+ Map<String, dynamic> toJson() {
+ return {
+ 'start': start.toIso8601String(),
+ 'end': end?.toIso8601String(),
+ 'type': type.toString(),
+ 'isActive': isActive.toString(),
+ };
+ }
+
Widget getStatusIcon() {
- if (end == null &&
- start.isBefore(DateTime.now()) &&
- !DateUtilities.DateUtils.isSameDay(start, DateTime.now())) {
+ if (shiftIsOpenButBeforeToday()) {
return Icon(Icons.pending);
}
if (getIsActive() && end == null) {
@@ -88,6 +101,12 @@ class Shift {
return 0.22916666;
}
+ bool shiftIsOpenButBeforeToday() {
+ return end == null &&
+ start.isBefore(DateTime.now()) &&
+ !DateUtilities.DateUtils.isSameDay(start, DateTime.now());
+ }
+
double getMoneyForActiveSession() {
if (getIsActive()) {
Duration elapsed = DateTime.now().difference(start);
@@ -120,9 +139,7 @@ class Shift {
}
Color getStatusColor() {
- if (end == null &&
- start.isBefore(DateTime.now()) &&
- !DateUtilities.DateUtils.isSameDay(start, DateTime.now())) {
+ if (shiftIsOpenButBeforeToday()) {
return Colors.orange;
}
if (getIsActive() && end == null) {