From 5edf49189865662dce192a1cb7c3b59714477af8 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Wed, 26 May 2021 16:45:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9date=20record=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/provider/app_provider.dart | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 5f03cd1..d05a0a5 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -1,4 +1,5 @@ // Flutter imports: +import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -90,17 +91,23 @@ class AppProvider extends ChangeNotifier { DateTime get clockOutTime => _clockOutTime; initClock() { + DateUtil.isToday(_dateRecord.millisecondsSinceEpoch.abs()); + // if (_dateRecord == null || + // (_dateRecord != + // DateTime.utc(DateTime.now().year, DateTime.now().month, + // DateTime.now().day))) { + // resetClock(); + // } + if (_dateRecord == null || - (_dateRecord != - DateTime.utc(DateTime.now().year, DateTime.now().month, - DateTime.now().day))) { + (!DateUtils.isSameDay(_dateRecord, DateTime.now()))) { resetClock(); } } setClockInTime(DateTime dateTime) { if (_clockStatus == WORKCLOCK.NOTIN) { - _dateRecord = DateTime.utc(dateTime.year, dateTime.month, dateTime.day); + _dateRecord = dateTime; _clockInTime = dateTime; _clockStatus = WORKCLOCK.IN; } @@ -108,14 +115,18 @@ class AppProvider extends ChangeNotifier { } setClockOutTime(DateTime dateTime) { + // if (_dateRecord != null && + // (_dateRecord != + // DateTime.utc(DateTime.now().year, DateTime.now().month, + // DateTime.now().day))) { + // resetClock(); + // } if (_dateRecord != null && - (_dateRecord != - DateTime.utc(DateTime.now().year, DateTime.now().month, - DateTime.now().day))) { + (!DateUtils.isSameDay(_dateRecord, DateTime.now()))) { resetClock(); } if (_clockStatus == WORKCLOCK.IN) { - _dateRecord = DateTime.utc(dateTime.year, dateTime.month, dateTime.day); + _dateRecord = dateTime; _clockOutTime = dateTime; _clockStatus = WORKCLOCK.OUT; }