48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
|
import 'package:smoke_cess_app/utils/timer_util.dart';
|
|
|
|
class Sleep implements DatabaseRecord {
|
|
final int _sleepQualityValue;
|
|
final String _comment;
|
|
final DateTime _date;
|
|
final TimeOfDay _sleptAt;
|
|
final TimeOfDay _wokeUpAt;
|
|
|
|
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleptAt,
|
|
this._wokeUpAt);
|
|
|
|
DateTime get date => _date;
|
|
String get comment => _comment;
|
|
int get sleepQualitiyValue => _sleepQualityValue;
|
|
TimeOfDay get sleepDuration => _sleptAt.durationBetween(_wokeUpAt);
|
|
|
|
@override
|
|
factory Sleep.fromDatabase(Map<String, dynamic> map) {
|
|
DateTime date = DateTime.parse(map['date']);
|
|
TimeOfDay sleptAt =
|
|
TimeOfDay(hour: map['sleptAtHour'], minute: map['sleptAtMinute']);
|
|
TimeOfDay wokeUpAt =
|
|
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
|
|
return Sleep(map['value'], map['comment'], date, sleptAt, wokeUpAt);
|
|
}
|
|
|
|
@override
|
|
String toCSV() {
|
|
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleptAt.hour}:${_sleptAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
|
|
}
|
|
|
|
@override
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'value': _sleepQualityValue,
|
|
'comment': _comment,
|
|
'date': _date.toIso8601String(),
|
|
'sleptAtHour': _sleptAt.hour,
|
|
'sleptAtMinute': _sleptAt.minute,
|
|
'wokeUpAtHour': _wokeUpAt.hour,
|
|
'wokeUpAtMinute': _wokeUpAt.minute,
|
|
};
|
|
}
|
|
}
|