[GH-ISSUE #2208] [FR] Move date parsing and formatting to the frontend #901

Closed
opened 2026-03-23 20:42:51 +00:00 by mirror · 1 comment
Owner

Originally created by @richardshiue on GitHub (Apr 6, 2023).
Original GitHub issue: https://github.com/AppFlowy-IO/AppFlowy/issues/2208

Description

Currently, all the time parsing and formatting for date cells is done in the backend. I wish to move all of this to the frontend and the backend will only store the timestamp and the include_time flag.

Pros:

  • will be able to readily translate date strings into other languages (e.g. lundi or Monday). The backend currently does not do any translation at all, and maybe shouldn't either.
  • will be able to readily adapt to the current locale (locale-specific date formats)
  • will be able to readily reference the current timezone and adapt to locale changes.

Cons:

  • no centralized parsing and formatting for other frontends, need to be separately implemented (Tauri)
  • no centralized testing in the backend
  • differs from other field types where the cell data is converted to a readable format using the field type options

Can I get some feedback before starting work on this?

Impact

Improves date field type and makes it easier to extend for future features

Additional Context

No response

Originally created by @richardshiue on GitHub (Apr 6, 2023). Original GitHub issue: https://github.com/AppFlowy-IO/AppFlowy/issues/2208 ### Description Currently, all the time parsing and formatting for date cells is done in the backend. I wish to move all of this to the frontend and the backend will only store the timestamp and the include_time flag. Pros: - will be able to readily translate date strings into other languages (e.g. lundi or Monday). The backend currently does not do any translation at all, and maybe shouldn't either. - will be able to readily adapt to the current locale ([locale-specific date formats](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#producing-normal-date-formats-for-a-locale)) - will be able to readily reference the current timezone and adapt to locale changes. Cons: - no centralized parsing and formatting for other frontends, need to be separately implemented (Tauri) - no centralized testing in the backend - differs from other field types where the cell data is converted to a readable format using the field type options Can I get some feedback before starting work on this? ### Impact Improves date field type and makes it easier to extend for future features ### Additional Context _No response_
Author
Owner

@appflowy commented on GitHub (Apr 7, 2023):

I am a fan of don't repeat code. So this is why I put the logic in the backend. Different UI framework share the same logic.
n Rust, you can calculate the current time with UTC using the chrono and chrone_tz

For example, we can get the time offset from Local. Then we can use the time with the stored UTC timestamp.

use chrono::{FixedOffset, NaiveDateTime};

#[test]
fn utc_to_native() {
  use chrono::Local;
  let timestamp = 1647251762;
  let native = NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap();

  let offset = Local::now().offset().clone();
  let auto_timezone = chrono::DateTime::<chrono::Local>::from_utc(native, offset);
  println!("{}", auto_timezone);

  let utc_7_offset = FixedOffset::east_opt(7 * 3600).unwrap();
  let utc_7_timezone = chrono::DateTime::<chrono::Local>::from_utc(native, utc_7_offset);
  println!("{}", utc_7_timezone);
}

<!-- gh-comment-id:1499843080 --> @appflowy commented on GitHub (Apr 7, 2023): I am a fan of `don't repeat code`. So this is why I put the logic in the backend. Different UI framework share the same logic. n Rust, you can calculate the current time with UTC using the `chrono` and `chrone_tz` For example, we can get the time offset from `Local`. Then we can use the time with the stored UTC timestamp. ```rust use chrono::{FixedOffset, NaiveDateTime}; #[test] fn utc_to_native() { use chrono::Local; let timestamp = 1647251762; let native = NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(); let offset = Local::now().offset().clone(); let auto_timezone = chrono::DateTime::<chrono::Local>::from_utc(native, offset); println!("{}", auto_timezone); let utc_7_offset = FixedOffset::east_opt(7 * 3600).unwrap(); let utc_7_timezone = chrono::DateTime::<chrono::Local>::from_utc(native, utc_7_offset); println!("{}", utc_7_timezone); } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
AppFlowy-IO/AppFlowy#901
No description provided.