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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix(flutter): wrong time zone when filtering by date field (#6543)
Richard Shiue8126d1968272
diff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yamlindex f47fc0d67a..2f4f47a0d8 100644--- a/.github/workflows/rust_ci.yaml+++ b/.github/workflows/rust_ci.yaml@@ -28,6 +28,11 @@ jobs:if: github.event.pull_request.head.repo.full_name == github.repositoryruns-on: self-hostedsteps:+ - name: Set timezone for action+ uses: szenius/[email protected]+ with:+ timezoneLinux: "US/Pacific"+- name: Checkout source codeuses: actions/checkout@v4@@ -94,6 +99,11 @@ jobs:if: github.event.pull_request.head.repo.full_name != github.repositoryruns-on: ubuntu-lateststeps:+ - name: Set timezone for action+ uses: szenius/[email protected]+ with:+ timezoneLinux: "US/Pacific"+- name: Maximize build spacerun: |sudo rm -rf /usr/share/dotnetdiff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dartindex 48d24614fe..a43c1bec47 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart@@ -117,7 +117,10 @@ class FilterEditorBloc extends Bloc<FilterEditorEvent, FilterEditorState> {case FieldType.DateTime:case FieldType.LastEditedTime:case FieldType.CreatedTime:- final timestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;+ final now = DateTime.now();+ final timestamp =+ DateTime(now.year, now.month, now.day).millisecondsSinceEpoch ~/+ 1000;return _filterBackendSvc.insertDateFilter(filterId: filterId,fieldId: fieldId,diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rsindex 2b3f58b177..6aea621326 100644--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs@@ -3,7 +3,7 @@ use crate::services::cell::insert_date_cell;use crate::services::field::TimestampCellData;use crate::services::filter::PreFillCellsWithFilter;-use chrono::{Duration, NaiveDate};+use chrono::{Duration, Local, NaiveDate, TimeZone};use collab_database::fields::date_type_option::DateCellData;use collab_database::fields::Field;use collab_database::rows::Cell;@@ -67,7 +67,10 @@ impl DateFilterPB {#[inline]fn naive_date_from_timestamp(timestamp: i64) -> Option<NaiveDate> {- chrono::DateTime::from_timestamp(timestamp, 0).map(|date| date.naive_utc().date())+ Local+ .timestamp_opt(timestamp, 0)+ .single()+ .map(|date_time| date_time.date_naive())}enum DateFilterStrategy {@@ -139,20 +142,32 @@ impl PreFillCellsWithFilter for DateFilterPB {DateFilterConditionPB::DateStartsBefore | DateFilterConditionPB::DateEndsBefore => self.timestamp.and_then(|timestamp| {- chrono::DateTime::from_timestamp(timestamp, 0).map(|date| date.naive_utc())+ Local+ .timestamp_opt(timestamp, 0)+ .single()+ .map(|date| date.naive_local())})- .map(|date_time| {+ .and_then(|date_time| {let answer = date_time - Duration::days(1);- answer.and_utc().timestamp()+ Local+ .from_local_datetime(&answer)+ .single()+ .map(|date_time| date_time.timestamp())}),DateFilterConditionPB::DateStartsAfter | DateFilterConditionPB::DateEndsAfter => self.timestamp.and_then(|timestamp| {- chrono::DateTime::from_timestamp(timestamp, 0).map(|date| date.naive_utc())+ Local+ .timestamp_opt(timestamp, 0)+ .single()+ .map(|date| date.naive_local())})- .map(|date_time| {+ .and_then(|date_time| {let answer = date_time + Duration::days(1);- answer.and_utc().timestamp()+ Local+ .from_local_datetime(&answer)+ .single()+ .map(|date_time| date_time.timestamp())}),DateFilterConditionPB::DateStartsBetween | DateFilterConditionPB::DateEndsBetween => {self.start@@ -381,4 +396,185 @@ mod tests {);}}++ #[test]+ fn timezoned_filter_test() {+ let filter = DateFilterPB {+ condition: DateFilterConditionPB::DateStartsOn,+ timestamp: Some(1728975660), // Oct 15, 2024 00:00 PDT+ end: None,+ start: None,+ };++ for (start, end, is_visible, msg) in [+ (+ Some(1728889200),+ None,+ false,+ "10/14/2024 00:00 PDT, 10/14/2024 07:00 GMT",+ ),+ (+ Some(1728889260),+ None,+ false,+ "10/14/2024 00:01 PDT, 10/14/2024 07:01 GMT",+ ),+ (+ Some(1728900000),+ None,+ false,+ "10/14/2024 03:00 PDT, 10/14/2024 10:00 GMT",+ ),+ (+ Some(1728921600),+ None,+ false,+ "10/14/2024 09:00 PDT, 10/14/2024 16:00 GMT",+ ),+ (+ Some(1728932400),+ None,+ false,+ "10/14/2024 12:00 PDT, 10/14/2024 19:00 GMT",+ ),+ (+ Some(1728943200),+ None,+ false,+ "10/14/2024 15:00 PDT, 10/14/2024 22:00 GMT",+ ),+ (+ Some(1728954000),+ None,+ false,+ "10/14/2024 18:00 PDT, 10/15/2024 01:00 GMT",+ ),+ (+ Some(1728964800),+ None,+ false,+ "10/14/2024 21:00 PDT, 10/15/2024 04:00 GMT",+ ),+ (+ Some(1728975540),+ None,+ false,+ "10/14/2024 23:59 PDT, 10/15/2024 06:59 GMT",+ ),+ (+ Some(1728975600),+ None,+ true,+ "10/15/2024 00:00 PDT, 10/15/2024 07:00 GMT",+ ),+ (+ Some(1728975660),+ None,+ true,+ "10/15/2024 00:01 PDT, 10/15/2024 07:01 GMT",+ ),+ (+ Some(1728986400),+ None,+ true,+ "10/15/2024 03:00 PDT, 10/15/2024 10:00 GMT",+ ),+ (+ Some(1729008000),+ None,+ true,+ "10/15/2024 09:00 PDT, 10/15/2024 16:00 GMT",+ ),+ (+ Some(1729018800),+ None,+ true,+ "10/15/2024 12:00 PDT, 10/15/2024 19:00 GMT",+ ),+ (+ Some(1729029600),+ None,+ true,+ "10/15/2024 15:00 PDT, 10/15/2024 22:00 GMT",+ ),+ (+ Some(1729040400),+ None,+ true,+ "10/15/2024 18:00 PDT, 10/16/2024 01:00 GMT",+ ),+ (+ Some(1729051200),+ None,+ true,+ "10/15/2024 21:00 PDT, 10/16/2024 04:00 GMT",+ ),+ (+ Some(1729061940),+ None,+ true,+ "10/15/2024 23:59 PDT, 10/16/2024 06:59 GMT",+ ),+ (+ Some(1729062000),+ None,+ false,+ "10/16/2024 00:00 PDT, 10/16/2024 07:00 GMT",+ ),+ (+ Some(1729062060),+ None,+ false,+ "10/16/2024 00:01 PDT, 10/16/2024 07:01 GMT",+ ),+ (+ Some(1729072800),+ None,+ false,+ "10/16/2024 03:00 PDT, 10/16/2024 10:00 GMT",+ ),+ (+ Some(1729094400),+ None,+ false,+ "10/16/2024 09:00 PDT, 10/16/2024 16:00 GMT",+ ),+ (+ Some(1729105200),+ None,+ false,+ "10/16/2024 12:00 PDT, 10/16/2024 19:00 GMT",+ ),+ (+ Some(1729116000),+ None,+ false,+ "10/16/2024 15:00 PDT, 10/16/2024 22:00 GMT",+ ),+ (+ Some(1729126800),+ None,+ false,+ "10/16/2024 18:00 PDT, 10/17/2024 01:00 GMT",+ ),+ (+ Some(1729137600),+ None,+ false,+ "10/16/2024 21:00 PDT, 10/17/2024 04:00 GMT",+ ),+ (+ Some(1729148340),+ None,+ false,+ "10/16/2024 23:59 PDT, 10/17/2024 06:59 GMT",+ ),+ ] {+ assert_eq!(+ filter.is_visible(&to_cell_data(start, end)).unwrap_or(true),+ is_visible,+ "{msg}"+ );+ }+ }}