TF-2042 Add event time information widget

(cherry picked from commit 5bfa21a8c426a794dfc5f1036c00c31f3069f77f)
This commit is contained in:
dab246
2023-07-26 18:49:33 +07:00
committed by Dat Vu
parent f287af8c37
commit 9f3fd56fa3
6 changed files with 167 additions and 1 deletions
@@ -180,6 +180,8 @@ extension CalendarEventExtension on CalendarEvent {
DateTime? get localStartDate => startUtcDate?.value.toLocal();
DateTime? get localEndDate => endUtcDate?.value.toLocal();
String get monthStartDateAsString {
if (localStartDate != null) {
return date_format.formatDate(
@@ -215,4 +217,56 @@ extension CalendarEventExtension on CalendarEvent {
return '';
}
}
String formatDateTime(DateTime dateTime) {
return date_format.formatDate(
dateTime,
[
date_format.DD,
', ',
date_format.MM,
' ',
date_format.dd,
', ',
date_format.yyyy,
' ',
date_format.hh,
':',
date_format.ss,
' ',
date_format.am
],
locale: AppUtils.getCurrentDateLocale()
);
}
String formatTime(DateTime dateTime) {
return date_format.formatDate(
dateTime,
[
date_format.hh,
':',
date_format.ss,
' ',
date_format.am
],
locale: AppUtils.getCurrentDateLocale()
);
}
String get dateTimeEventAsString {
if (localStartDate != null && localEndDate != null) {
final timeStart = formatDateTime(localStartDate!);
final timeEnd = DateUtils.isSameDay(localStartDate, localEndDate)
? formatTime(localEndDate!)
: formatDateTime(localEndDate!);
return '$timeStart - $timeEnd';
} else if (localStartDate != null) {
return formatDateTime(localStartDate!);
} else if (localEndDate != null) {
return formatDateTime(localEndDate!);
} else {
return '';
}
}
}