[feature proposal] Local time zone in timestamps #2878

Closed
opened 2025-11-02 04:52:22 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @oscarlofwenhamn on GitHub (Feb 8, 2019).

  • Gitea version (or commit ref): 1.7.1
  • Git version: n/a
  • Operating system: RHEL 7.5
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist: n/a

Description

As a user, I would like to (at least have the option to) see timestamps presented in my local timezone. As several users can be located in different time zones, it would be a better experience to see timestamps presented in a way that corresponds to the local time.

My local solution to this is a short script that adjusts the stamp using the js Date-function placed in the footer:

window.onload=function(){
    var times = document.getElementsByClassName("time-since");
    for (var i = 0; i<times.length; i++){
		var localTime = new Date(times[i].getAttribute("data-content"));
		if(localTime != "Invalid Date"){
			times[i].setAttribute("data-content", localTime.toString());
		}
    }
}

though as I am not very experienced in javascript, a better solution is probably possible. Regardless of implementation, this is my proposal.

Screenshots

Current
image

Proposed
image

Originally created by @oscarlofwenhamn on GitHub (Feb 8, 2019). <!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.7.1 - Git version: n/a - Operating system: RHEL 7.5 - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: n/a ## Description As a user, I would like to (at least have the option to) see timestamps presented in my local timezone. As several users can be located in different time zones, it would be a better experience to see timestamps presented in a way that corresponds to the local time. My local solution to this is a short script that adjusts the stamp using the js Date-function placed in the footer: ```javascript window.onload=function(){ var times = document.getElementsByClassName("time-since"); for (var i = 0; i<times.length; i++){ var localTime = new Date(times[i].getAttribute("data-content")); if(localTime != "Invalid Date"){ times[i].setAttribute("data-content", localTime.toString()); } } } ``` though as I am not very experienced in javascript, a better solution is probably possible. Regardless of implementation, this is my proposal. ## Screenshots Current ![image](https://user-images.githubusercontent.com/44643697/52482828-9c6be300-2bb2-11e9-8701-88d5f12944f6.png) Proposed ![image](https://user-images.githubusercontent.com/44643697/52482959-ed7bd700-2bb2-11e9-87ed-3630e891e6ed.png) <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/proposaltype/enhancement labels 2025-11-02 04:52:22 -06:00
Author
Owner

@oscarlofwenhamn commented on GitHub (Feb 8, 2019):

In order to get rid of the "(Central European Standard Time)", i added a regex replace, ending up with

localTime.toString().replace(/ *\([^)]*\) */g, "")

which brings it all down to a more similar ui size as the original.

@oscarlofwenhamn commented on GitHub (Feb 8, 2019): In order to get rid of the "(Central European Standard Time)", i added a regex replace, ending up with ```javascript localTime.toString().replace(/ *\([^)]*\) */g, "") ``` which brings it all down to a more similar ui size as the original.
Author
Owner

@NateScarlet commented on GitHub (Mar 14, 2019):

Good work
Maybe you should use localTime.toLocaleString
This function give a translated result
image

@NateScarlet commented on GitHub (Mar 14, 2019): Good work Maybe you should use `localTime.toLocaleString` This function give a translated result ![image](https://user-images.githubusercontent.com/21083014/54326457-5f778e00-4641-11e9-9258-fef80e821411.png)
Author
Owner

@NateScarlet commented on GitHub (Mar 14, 2019):

A userscript to use with current version:

// ==UserScript==
// @name     Gitea local time
// @version  1
// @run-at   document-end
// @include  *
// ==/UserScript==

(function() {
  /**
   * @type {HTMLMetaElement}
   */
  const meta = document.querySelector('meta[name=keywords]');
  if (!(meta && meta.content.split(',').includes('gitea'))) {
    return;
  }
  /**
   * @type {NodeListOf<HTMLSpanElement>}
   */
  const times = document.querySelectorAll('span.time-since.poping.up');
  for (const i of times) {
    const localTime = new Date(i.dataset.content);
    if (isNaN(localTime)) {
      continue;
    }
    i.dataset.content = localTime.toLocaleString();
  }
})();
@NateScarlet commented on GitHub (Mar 14, 2019): A userscript to use with current version: ```js // ==UserScript== // @name Gitea local time // @version 1 // @run-at document-end // @include * // ==/UserScript== (function() { /** * @type {HTMLMetaElement} */ const meta = document.querySelector('meta[name=keywords]'); if (!(meta && meta.content.split(',').includes('gitea'))) { return; } /** * @type {NodeListOf<HTMLSpanElement>} */ const times = document.querySelectorAll('span.time-since.poping.up'); for (const i of times) { const localTime = new Date(i.dataset.content); if (isNaN(localTime)) { continue; } i.dataset.content = localTime.toLocaleString(); } })(); ```
Author
Owner

@lunny commented on GitHub (Mar 14, 2019):

@NateScarlet could you send a PR to fix that?

@lunny commented on GitHub (Mar 14, 2019): @NateScarlet could you send a PR to fix that?
Author
Owner

@oscarlofwenhamn commented on GitHub (Mar 14, 2019):

Brilliant, nice addition @NateScarlet. And thanks for the help with a PR, I haven't been sure enough of my solution and the workflow to make one.

@oscarlofwenhamn commented on GitHub (Mar 14, 2019): Brilliant, nice addition @NateScarlet. And thanks for the help with a PR, I haven't been sure enough of my solution and the workflow to make one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2878