scancode.io icon indicating copy to clipboard operation
scancode.io copied to clipboard

Display dates in local time

Open cco3 opened this issue 3 years ago • 9 comments

The Web UI currently displays thing like the "Created time", etc. using UTC time, but it might make sense to use local time or both UTC and local time.

(I was having trouble figuring out which scan I was looking at..."was this the one I started at 8:00 or at 11:00?")

cco3 avatar Apr 08 '21 16:04 cco3

@cco3 Summary of changes about "dates" in latest version:

  • The local installation timezone can now be configured using the TIME_ZONE settings. See https://scancodeio.readthedocs.io/en/latest/scancodeio-settings.html#time-zone for details.
  • The current timezone is now displayed along the date in the web UI.
  • The creation date of a project is displayed as a more readable "Created 6 hours ago", the full date information can be displayed hovering the date label: date

tdruez avatar Apr 28 '21 12:04 tdruez

By "The current timezone", do you mean the timezone specified in the settings? Why not just let the client display the time according to the local timezone?

cco3 avatar Apr 30 '21 01:04 cco3

@cco3

By "The current timezone", do you mean the timezone specified in the settings?

Yes, Django allows to specify the timezone of the server, not to get the timezone for each clients. The dates are always stored as UTC in the database and displayed using the server defined timezone (TIME_ZONE settings).

Why not just let the client display the time according to the local timezone?

If by "local timezone" you mean "client timezone" rather than "server timezone", how would you get that information from the client?

tdruez avatar May 06 '21 14:05 tdruez

The server serves up UTC. The client then displays it according to the local timezone (i.e., using javascript). new Date(utcTimestamp).toString() would be one example that works in chrome.

Unfortunately the standard javascript time functions are very inconsistent across browsers, but there are libraries commonly used to fix that.

cco3 avatar May 06 '21 19:05 cco3

Times are still being shown in UTC:

Screenshot from 2021-08-06 11-32-21

cco3 avatar Aug 06 '21 18:08 cco3

v30.2.0

It works on setting the value for the TIME_ZONE variable in the env

time_env_zone

when variable value is set to IST

time_ist

when variable has no value set it's UTC

time_utc

lf32 avatar Apr 15 '22 10:04 lf32

why geo when value can be set directly in the settings?

lf32 avatar Apr 15 '22 10:04 lf32

@lf32 Thank you for the excellent research! Note that's changing the date system-wide including in the DB... which may not always be what one wants and may be keeping UTC there is simpler... The alternative is only to display a "local time" based on a web user date The trick is to get the user date/time setting which is not something Django handles and is typically best done clien-side with JS afaik. See for instance https://github.com/adamcharnock/django-tz-detect

See also https://docs.djangoproject.com/en/4.0/topics/i18n/timezones/#template-tags

@cco3 Would be changing the setting be enough for you?

pombredanne avatar Apr 15 '22 14:04 pombredanne

@pombredanne Thank you, I'll check them

lf32 avatar Apr 15 '22 16:04 lf32