diff --git a/lib/features/manage_account/presentation/extensions/datetime_extension.dart b/lib/features/manage_account/presentation/extensions/datetime_extension.dart index ce96ccf18..e96bf8070 100644 --- a/lib/features/manage_account/presentation/extensions/datetime_extension.dart +++ b/lib/features/manage_account/presentation/extensions/datetime_extension.dart @@ -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; } diff --git a/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart b/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart index 9a1f0ca9f..24fbbb21e 100644 --- a/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart +++ b/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart @@ -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 { diff --git a/lib/features/manage_account/presentation/model/vacation/vacation_presentation.dart b/lib/features/manage_account/presentation/model/vacation/vacation_presentation.dart index f16c24a94..75a66bac1 100644 --- a/lib/features/manage_account/presentation/model/vacation/vacation_presentation.dart +++ b/lib/features/manage_account/presentation/model/vacation/vacation_presentation.dart @@ -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, diff --git a/model/lib/extensions/utc_date_extension.dart b/model/lib/extensions/utc_date_extension.dart index 324ac65eb..8e5c4285b 100644 --- a/model/lib/extensions/utc_date_extension.dart +++ b/model/lib/extensions/utc_date_extension.dart @@ -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 ''; - } - } } \ No newline at end of file