cpd_2022_zi/lib/models/sleep.dart

42 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:smoke_cess_app/interface/db_record.dart';
class Sleep implements DatabaseRecord {
final int _sleepQualityValue;
final String _comment;
final DateTime _date;
final TimeOfDay _sleepedAt;
final TimeOfDay _wokeUpAt;
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt,
this._wokeUpAt);
@override
factory Sleep.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
TimeOfDay sleepedAt =
TimeOfDay(hour: map['sleepedAtHour'], minute: map['sleepedAtMinute']);
TimeOfDay wokeUpAt =
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
return Sleep(map['value'], map['comment'], date, sleepedAt, wokeUpAt);
}
@override
String toCSV() {
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleepedAt.hour}:${_sleepedAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
}
@override
Map<String, dynamic> toMap() {
return {
'value': _sleepQualityValue,
'comment': _comment,
'date': _date.toIso8601String(),
'sleepedAtHour': _sleepedAt.hour,
'sleepedAtMinute': _sleepedAt.minute,
'wokeUpAtHour': _wokeUpAt.hour,
'wokeUpAtMinute': _wokeUpAt.minute,
};
}
}