Skip to content

[feature proposal] Local time zone in timestamps #6004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 7 tasks
oscarlofwenhamn opened this issue Feb 8, 2019 · 5 comments · Fixed by #6324
Closed
2 of 7 tasks

[feature proposal] Local time zone in timestamps #6004

oscarlofwenhamn opened this issue Feb 8, 2019 · 5 comments · Fixed by #6324
Labels
type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@oscarlofwenhamn
Copy link
Contributor

  • 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

@lunny lunny added type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Feb 8, 2019
@oscarlofwenhamn
Copy link
Contributor Author

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.

@NateScarlet
Copy link
Contributor

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

@NateScarlet
Copy link
Contributor

NateScarlet commented 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();
  }
})();

@lunny
Copy link
Member

lunny commented Mar 14, 2019

@NateScarlet could you send a PR to fix that?

NateScarlet added a commit to NateScarlet/gitea that referenced this issue Mar 14, 2019
@oscarlofwenhamn
Copy link
Contributor Author

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.

lunny pushed a commit that referenced this issue Mar 20, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants