scancode.io
scancode.io copied to clipboard
Display dates in local time
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 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:
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
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?
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.
Times are still being shown in UTC:
v30.2.0
It works on setting the value for the TIME_ZONE
variable in the env
when variable value is set to IST
when variable has no value set it's UTC
why geo when value can be set directly in the settings?
@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 Thank you, I'll check them