util funciton to calculate duration between two times => calc sleepTime
parent
6c3915b6ab
commit
e7dc40a4de
|
@ -1,5 +1,6 @@
|
|||
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;
|
||||
|
@ -13,6 +14,7 @@ class Sleep implements DatabaseRecord {
|
|||
|
||||
DateTime get date => _date;
|
||||
int get sleepQualitiyValue => _sleepQualityValue;
|
||||
TimeOfDay get sleepDuration => _sleptAt.durationBetween(_wokeUpAt);
|
||||
|
||||
@override
|
||||
factory Sleep.fromDatabase(Map<String, dynamic> map) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
String formatTime(int seconds) {
|
||||
Duration duration = Duration(seconds: seconds);
|
||||
String formattedTime = '';
|
||||
|
@ -12,3 +14,12 @@ String formatTime(int seconds) {
|
|||
formattedTime += formattedSeconds;
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
extension TimeOfDayExtension on TimeOfDay {
|
||||
TimeOfDay durationBetween(TimeOfDay time) {
|
||||
int hourOffset = time.minute - minute < 0 ? 1 : 0;
|
||||
return TimeOfDay(
|
||||
hour: (time.hour - hour - hourOffset) % 24,
|
||||
minute: (time.minute - minute) % 60);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue