mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: default include time (#2444)
* fix: default include time * chore: clarify logic and add comments
This commit is contained in:
parent
db8d030a85
commit
5d0a349236
@ -45,12 +45,7 @@ class DateCellDataPersistence implements CellDataPersistence<DateCellData> {
|
||||
Future<Option<FlowyError>> save(DateCellData data) {
|
||||
var payload = DateChangesetPB.create()..cellPath = _makeCellPath(cellId);
|
||||
|
||||
// This is a bit of a hack. This converts the data.date which is in
|
||||
// UTC to Local but actually changes the timestamp instead of just
|
||||
// changing the isUtc flag
|
||||
final dateTime = DateTime(data.date.year, data.date.month, data.date.day);
|
||||
|
||||
final date = (dateTime.millisecondsSinceEpoch ~/ 1000).toString();
|
||||
final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
|
||||
payload.date = date;
|
||||
payload.isUtc = data.date.isUtc;
|
||||
payload.includeTime = data.includeTime;
|
||||
|
@ -84,15 +84,23 @@ class DateCellCalendarBloc
|
||||
bool? includeTime,
|
||||
}) {
|
||||
final DateCellData newDateData = state.dateCellData.fold(
|
||||
() => DateCellData(
|
||||
date: date ?? DateTime.now(),
|
||||
time: time,
|
||||
includeTime: includeTime ?? false,
|
||||
),
|
||||
() {
|
||||
DateTime newDate = DateTime.now();
|
||||
if (date != null) {
|
||||
newDate = _utcToLocalAddTime(date);
|
||||
}
|
||||
return DateCellData(
|
||||
date: newDate,
|
||||
time: time,
|
||||
includeTime: includeTime ?? false,
|
||||
);
|
||||
},
|
||||
(dateData) {
|
||||
var newDateData = dateData;
|
||||
if (date != null && !isSameDay(newDateData.date, date)) {
|
||||
newDateData = newDateData.copyWith(date: date);
|
||||
newDateData = newDateData.copyWith(
|
||||
date: _utcToLocalAddTime(date),
|
||||
);
|
||||
}
|
||||
|
||||
if (newDateData.time != time) {
|
||||
@ -151,6 +159,21 @@ class DateCellCalendarBloc
|
||||
);
|
||||
}
|
||||
|
||||
DateTime _utcToLocalAddTime(DateTime date) {
|
||||
final now = DateTime.now();
|
||||
// the incoming date is Utc. this trick converts it into Local
|
||||
// and add the current time, though
|
||||
// the time may be overwritten by explicitly provided time string
|
||||
return DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
now.hour,
|
||||
now.minute,
|
||||
now.second,
|
||||
);
|
||||
}
|
||||
|
||||
String timeFormatPrompt(FlowyError error) {
|
||||
String msg = "${LocaleKeys.grid_field_invalidTimeFormat.tr()}.";
|
||||
switch (state.dateTypeOptionPB.timeFormat) {
|
||||
|
Loading…
Reference in New Issue
Block a user