TF-1003 Fix select today as start date, can not receive vacation message

This commit is contained in:
dab246
2022-09-29 17:33:29 +07:00
committed by Dat H. Pham
parent 39749dcba9
commit 2c61102d03
4 changed files with 15 additions and 30 deletions
@@ -13,7 +13,7 @@ extension DateTimeExtension on DateTime? {
DateTime? applied(TimeOfDay? time) {
if (this != null && time != null) {
return DateTime.utc(this!.year, this!.month, this!.day, time.hour, time.minute);
return DateTime(this!.year, this!.month, this!.day, time.hour, time.minute);
}
return null;
}
@@ -1,5 +1,4 @@
import 'package:core/utils/app_logger.dart';
import 'package:flutter/material.dart';
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
@@ -15,13 +14,13 @@ extension VacationResponseExtension on VacationResponse {
status: isEnabled == true
? VacationResponderStatus.activated
: VacationResponderStatus.deactivated,
startDate: fromDate?.value.toUtc(),
startDate: fromDate?.value.toLocal(),
startTime: fromDate?.value != null
? TimeOfDay.fromDateTime(fromDate!.value.toUtc())
? TimeOfDay.fromDateTime(fromDate!.value.toLocal())
: null,
endDate: toDate?.value.toUtc(),
endDate: toDate?.value.toLocal(),
endTime: toDate?.value != null
? TimeOfDay.fromDateTime(toDate!.value.toUtc())
? TimeOfDay.fromDateTime(toDate!.value.toLocal())
: null,
messagePlainText: textBody,
messageHtmlText: htmlBody,
@@ -36,10 +35,8 @@ extension VacationResponseExtension on VacationResponse {
bool get vacationResponderIsReady {
if (isEnabled == true) {
final currentDate = DateTime.now().toUtc();
log('VacationResponseExtension::vacationResponderEnabled(): currentDate: $currentDate');
final startDate = fromDate?.value.toUtc();
log('VacationResponseExtension::vacationResponderEnabled(): startDate: $startDate');
final currentDate = DateTime.now();
final startDate = fromDate?.value.toLocal();
if (startDate != null && (startDate.isBefore(currentDate) ||
startDate.isAtSameMomentAs(currentDate))) {
return true;
@@ -52,10 +49,8 @@ extension VacationResponseExtension on VacationResponse {
bool get vacationResponderIsWaiting {
if (isEnabled == true) {
final currentDate = DateTime.now().toUtc();
log('VacationResponseExtension::vacationResponderIsWaiting(): currentDate: $currentDate');
final startDate = fromDate?.value.toUtc();
log('VacationResponseExtension::vacationResponderIsWaiting(): startDate: $startDate');
final currentDate = DateTime.now();
final startDate = fromDate?.value.toLocal();
if (startDate != null && startDate.isAfter(currentDate)) {
return true;
} else {
@@ -67,10 +62,8 @@ extension VacationResponseExtension on VacationResponse {
bool get vacationResponderIsStopped {
if (isEnabled == true) {
final currentDate = DateTime.now().toUtc();
log('VacationResponseExtension::vacationResponderIsStopped(): currentDate: $currentDate');
final endDate = toDate?.value.toUtc();
log('VacationResponseExtension::vacationResponderIsStopped(): endDate: $endDate');
final currentDate = DateTime.now();
final endDate = toDate?.value.toLocal();
if (endDate != null && endDate.isBefore(currentDate)) {
return true;
} else {
@@ -103,12 +96,12 @@ extension VacationResponseExtension on VacationResponse {
return AppLocalizations.of(context).yourVacationResponderIsEnabled;
} else if (vacationResponderIsWaiting) {
return AppLocalizations.of(context).messageEnableVacationResponderAutomatically(
fromDate.formatDate(
fromDate.formatDateToLocal(
pattern: 'MMM d, y h:mm a',
locale: Localizations.localeOf(context).toLanguageTag()));
} else if (vacationResponderIsStopped) {
return AppLocalizations.of(context).messageDisableVacationResponderAutomatically(
toDate.formatDate(
toDate.formatDateToLocal(
pattern: 'MMM d, y h:mm a',
locale: Localizations.localeOf(context).toLanguageTag()));
} else {
@@ -89,8 +89,8 @@ extension VacationPresentationExtension on VacationPresentation {
VacationResponse toVacationResponse() {
return VacationResponse(
isEnabled: isEnabled,
fromDate: fromDate != null ? UTCDate(fromDate!) : null,
toDate: toDate != null ? UTCDate(toDate!) : null,
fromDate: fromDate != null ? UTCDate(fromDate!.toUtc()) : null,
toDate: toDate != null ? UTCDate(toDate!.toUtc()) : null,
textBody: messagePlainText,
htmlBody: messageHtmlText,
subject: subject,
@@ -10,12 +10,4 @@ extension UTCDateExtension on UTCDate? {
return '';
}
}
String formatDate({String pattern = 'yMMMd', String locale = 'en_US'}) {
if (this != null) {
return DateFormat(pattern, locale).format(this!.value);
} else {
return '';
}
}
}