bugfix: adjust timestamp / 1000

welcome
98spag 2023-05-14 09:27:23 +02:00
parent 5d3f12c9a1
commit 558ad030c7
1 changed files with 5 additions and 4 deletions

View File

@ -19,7 +19,8 @@ class StatisticsService {
// Hive.deleteFromDisk(); // Hive.deleteFromDisk();
Box box = Hive.box(boxName); Box box = Hive.box(boxName);
DateTime dateTime = DateTime.now(); DateTime dateTime = DateTime.now();
int timestamp = dateTime.millisecondsSinceEpoch.toInt(); int timestamp = dateTime.millisecondsSinceEpoch.toInt() ~/ 1000;
print(timestamp);
Map<String, List<Food>>? valueMap = box.get(timestamp); Map<String, List<Food>>? valueMap = box.get(timestamp);
valueMap ??= { valueMap ??= {
"FRÜHSTÜCK": [], "FRÜHSTÜCK": [],
@ -38,7 +39,7 @@ class StatisticsService {
num getAllCaloriesByTimestamp(DateTime date){ num getAllCaloriesByTimestamp(DateTime date){
Box box = Hive.box(boxName); Box box = Hive.box(boxName);
int timestamp = date.millisecondsSinceEpoch.toInt(); int timestamp = date.millisecondsSinceEpoch.toInt() ~/ 1000;
Map<String, List<Food>>? valueMap = box.get(timestamp); Map<String, List<Food>>? valueMap = box.get(timestamp);
if(valueMap == null){ if(valueMap == null){
return 0; return 0;
@ -55,9 +56,9 @@ class StatisticsService {
return sum; return sum;
} }
num getCaloriesByTimestampAndMealType(DateTime timestamp, String mealType){ num getCaloriesByTimestampAndMealType(DateTime date, String mealType){
Box box = Hive.box(boxName); Box box = Hive.box(boxName);
int timestamp = date.millisecondsSinceEpoch.toInt() ~/ 1000;
Map<String, List<Food>>? valueMap = box.get(timestamp); Map<String, List<Food>>? valueMap = box.get(timestamp);
if(valueMap == null){ if(valueMap == null){
return 0; return 0;