question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store Unix Time instead of ISO formatted string

See original GitHub issue

Currently, we store datetime as an ISO formatted string (for example, "2022-03-23 20:58:40.584444").

This has the advantage of being human-readable. However, this comes with the big disadvantage that we don’t know what timezone we’re talking about. This leads to various problems. For example, when global users are updating documents. Or when the backend updates documents before and after the system timezone changes.

Some of these issues have been addressed already, for example, by trying to convert to and from the users’ timezone. However, the underlying issue remains: we’re storing times without the timezone.

A nice solution would be to store the Unix Time or UTC timestamp. (The unix time would also make comparing and calculating with times easy – after all, it’s just a number.) When we need to display the timestamp, we can convert it to the appropriate timezone.

Existing time stamps could be assumed to be in the timezone from System Settings, before conversion.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hrwXcommented, Jul 15, 2022

@barredterra @ankush

  • #13504 This PR kinda does the same, all the timezone in the database is stored in the default timezone, which is set during the setup, and then that field in system settings is read-only.
  • So if we have to keep the db in UTC, we just have to set UTC in System Settings, and it’ll just work!
  • But we cannot patch the existing system.
  • FYI this change was introduced since it fixes the issue of having multiple timezones in the db for multi-company/multi-country setup
1reaction
ankushcommented, Jul 18, 2022

We can modify the scheduler’s timezone to some other configured value if that’s only roadblocker. It’s a very localized changed in scheduler.py

It’s better to keep scheduler in local timezone because ERPNext has few events which are best triggered at midnight (imagine birthday reminders, would be weird af to receive them 5 hours before that day starts 😄)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are unix timestamps the best way to store timestamps?
If you prefer a more human readable format for storage than a Unix timestamp, consider ISO 8601. One technique that helps keep things...
Read more >
Do you prefer unix epoch (a number) or ISO 8601 (a string) for ...
I've seen Unix timestamps used in APIs but I've always used ISO UTC datetimes because I like they are readable both by humans...
Read more >
UNIX time is actually much easier to parse and more accurate ...
There are very few good reasons to choose a Unix timestamp to represent a date when compared with ISO-8601. Complete lack of string...
Read more >
Designing a REST API: Unix time vs ISO-8601
To fix this is ISO-8601. It presents the data in a well defined, human readable string format. This allows for easier development as...
Read more >
strtotime - Manual - PHP
The function expects to be given a string containing an English date format and will try to parse that format into a Unix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found