Skip to content

Commit 5d0a349

Browse files
authored
fix: default include time (#2444)
* fix: default include time * chore: clarify logic and add comments
1 parent db8d030 commit 5d0a349

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_persistence.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ class DateCellDataPersistence implements CellDataPersistence<DateCellData> {
4545
Future<Option<FlowyError>> save(DateCellData data) {
4646
var payload = DateChangesetPB.create()..cellPath = _makeCellPath(cellId);
4747

48-
// This is a bit of a hack. This converts the data.date which is in
49-
// UTC to Local but actually changes the timestamp instead of just
50-
// changing the isUtc flag
51-
final dateTime = DateTime(data.date.year, data.date.month, data.date.day);
52-
53-
final date = (dateTime.millisecondsSinceEpoch ~/ 1000).toString();
48+
final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
5449
payload.date = date;
5550
payload.isUtc = data.date.isUtc;
5651
payload.includeTime = data.includeTime;

frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cal_bloc.dart

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,23 @@ class DateCellCalendarBloc
8484
bool? includeTime,
8585
}) {
8686
final DateCellData newDateData = state.dateCellData.fold(
87-
() => DateCellData(
88-
date: date ?? DateTime.now(),
89-
time: time,
90-
includeTime: includeTime ?? false,
91-
),
87+
() {
88+
DateTime newDate = DateTime.now();
89+
if (date != null) {
90+
newDate = _utcToLocalAddTime(date);
91+
}
92+
return DateCellData(
93+
date: newDate,
94+
time: time,
95+
includeTime: includeTime ?? false,
96+
);
97+
},
9298
(dateData) {
9399
var newDateData = dateData;
94100
if (date != null && !isSameDay(newDateData.date, date)) {
95-
newDateData = newDateData.copyWith(date: date);
101+
newDateData = newDateData.copyWith(
102+
date: _utcToLocalAddTime(date),
103+
);
96104
}
97105

98106
if (newDateData.time != time) {
@@ -151,6 +159,21 @@ class DateCellCalendarBloc
151159
);
152160
}
153161

162+
DateTime _utcToLocalAddTime(DateTime date) {
163+
final now = DateTime.now();
164+
// the incoming date is Utc. this trick converts it into Local
165+
// and add the current time, though
166+
// the time may be overwritten by explicitly provided time string
167+
return DateTime(
168+
date.year,
169+
date.month,
170+
date.day,
171+
now.hour,
172+
now.minute,
173+
now.second,
174+
);
175+
}
176+
154177
String timeFormatPrompt(FlowyError error) {
155178
String msg = "${LocaleKeys.grid_field_invalidTimeFormat.tr()}.";
156179
switch (state.dateTypeOptionPB.timeFormat) {

0 commit comments

Comments
 (0)