Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: local time (#2436)

Richard Shiuec320f6ef8a5d
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_persistence.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_persistence.dart
index f0cb6531fa..dd5e56e08c 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_persistence.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_persistence.dart
@@ -45,7 +45,12 @@ class DateCellDataPersistence implements CellDataPersistence<DateCellData> {
Future<Option<FlowyError>> save(DateCellData data) {
var payload = DateChangesetPB.create()..cellPath = _makeCellPath(cellId);
- final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
+ // 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();
payload.date = date;
payload.isUtc = data.date.isUtc;
payload.includeTime = data.includeTime;
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cal_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cal_bloc.dart
index 1a0a78894c..ad88d0ec97 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cal_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cal_bloc.dart
@@ -290,10 +290,7 @@ Option<DateCellData> calDataFromCellData(DateCellDataPB? cellData) {
Option<DateCellData> dateData = none();
if (cellData != null) {
final timestamp = cellData.timestamp * 1000;
- final date = DateTime.fromMillisecondsSinceEpoch(
- timestamp.toInt(),
- isUtc: true,
- );
+ final date = DateTime.fromMillisecondsSinceEpoch(timestamp.toInt());
dateData = Some(
DateCellData(
date: date,
diff --git a/frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option.rs b/frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option.rs
index 4cd3444cf7..d38cf3247f 100644
--- a/frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option.rs
+++ b/frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option.rs
@@ -94,15 +94,22 @@ impl DateTypeOptionPB {
fn timestamp_from_utc_with_time(
&self,
- naive_date: &NaiveDateTime,
+ naive_date: NaiveDateTime,
time_str: &Option<String>,
) -> FlowyResult<i64> {
if let Some(time_str) = time_str.as_ref() {
if !time_str.is_empty() {
+ let offset = Local::now().offset().clone();
let naive_time = chrono::NaiveTime::parse_from_str(time_str, self.time_format.format_str());
return match naive_time {
- Ok(naive_time) => Ok(naive_date.date().and_time(naive_time).timestamp()),
+ Ok(naive_time) => {
+ let naive = chrono::DateTime::<Local>::from_utc(naive_date, offset)
+ .date_naive()
+ .and_time(naive_time);
+ let local = chrono::DateTime::<Local>::from_local(naive, offset);
+ Ok(local.timestamp())
+ },
Err(_e) => {
let msg = format!("Parse {} failed", time_str);
Err(FlowyError::new(ErrorCode::InvalidDateTimeFormat, &msg))
@@ -165,7 +172,7 @@ impl CellDataChangeset for DateTypeOptionPB {
let time = Some(time.trim().to_uppercase());
let naive = NaiveDateTime::from_timestamp_opt(date_timestamp, 0);
if let Some(naive) = naive {
- Some(self.timestamp_from_utc_with_time(&naive, &time)?)
+ Some(self.timestamp_from_utc_with_time(naive, &time)?)
} else {
Some(date_timestamp)
}