How to change date format?

Everything’s great except one thing: the date format. I just can’t work with “3 month ago”. I don’t want to hover over each item to see the actual date. I need to change all date output (issues, commits, wiki-page-edits, …) to absolute format. How would I do that?

1 Like

Unfortunately I believe this would require changes in a large number of templates. That string is created in the template and then displayed (example)

Thank you very much for the reply. I need to change that, no matter how many files I have to change. I really want to keep using gitea but this date format is unbearable.

Could I please bother you to go a bit more into detail? Right now, I don’t see where the output I am looking for could be generated in the source you’ve linked. I fail to see how that file could be changed to generate the desired output format (at least for some elements).

Here’s an example of the current output:

<span class="time-since poping up visible" title="" data-content="Wed, 22 Apr 2020 15:30:39 CEST" data-variation="inverted tiny">2 weeks ago</span>

As you can see, in the attribute data-content already holds the value in a much preferable format.

In the source code you’ve linked in your reply the line
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}
does look kinda promising. Additionally it would be very interesting, what all those lines do, that look like this:
{{$.i18n.Tr "repo.issues.reopened_at" .EventTag $createdStr | Safe}}
still I can’t make much out of it. I am guessing that $.i18n.Tr points to the translation function.

After looking into it more, it seems this is all determined in the backend.

Note that the format you prefer is actually placed in the title attribute, however when the JS transforms it, it is moved to data-content

I believe in order to get what you want, you may have to change the source code itself, or put an issue in on GitHub and someone may pick it up to allow customizing that output.

Thank you very much for your reply jolheiser, sorry for the late answer.

I do not have any experience with the go language. Sadly I don’t have the time to get into the language and try to adjust the code myself. I do not know go syntax and I haven’t spent much time analysing the template mechanics. Still, in the line of code you’ve posted on your first reply

{{ createdStr:= TimeSinceUnix .CreatedUnix .Lang }}

it looks like “TimeSinceUnix” is a function call (I’m just guessing) and “.CreatedUnix” and “$.Lang” are it’s arguments. Wouldn’t it be possible to fill the variable “$createdStr” with the result of another function in that place? Would it be possible to call some basic time-to-string function or am I completely wrong here?

“// TimeSinceUnix calculates the time interval and generate user-friendly string.”

It’s so beyond me how anybody could think that this would be user friendly. Just now I need to prepare a detailed activity report for a funding body that also has to cover the time when we were using just gitea (we started using an additional project management software that’s why the issue didn’t bother me lately). How should it help me when I look at the list of issues and every entry says “one year ago”???

Seriously, how is it possible that nobody else but me is driven crazy because of this “user-friendly” date format? How should anybody be able to create management reports from this? I admit that it might be kinda nice when you’re dealing with the current day or maybe the current week but that’s all.

Kind regards

Changing the line

{{ createdStr:= TimeSinceUnix .CreatedUnix .Lang }}

to

{{ $createdStr:= .CreatedUnix.Format “am 02.01.2006 um 15:04:05 Uhr” }}
edit: removed link to gitea source code here /edit

Fixed the issue for me. So far only for the comments.

I had to use a function of the class timeutil and I had to hard code the German data format. But that’s fine with me for now.

Now I have to find all templates calling the function TimeSinceUnix and apply the same change there.

Kind regards

Where do I find correct template?

I’m using the most current version of gitea.
Gitea version 1.13.3 built with GNU Make 4.1, go1.15.8 : bindata, sqlite, sqlite_unlock_notify

I’ve downloaded templates from github go-gitea/gitea (posting link to that host is not allowed here)

I can’t start gitea because those templates contain unkown functions

gitea[10864]: panic: template: shared/issuelist:130: function “avatar” not defined
gitea[11214]: panic: template: user/dashboard/feeds:4: function “avatarByAction” not defined
gitea[11561]: panic: template: user/dashboard/feeds:95: function “avatarHTML” not defined

what am I doing wrong here?

please reconsider flagging previous posts as spam. that is completely uncalled for. I’d understand if you’d say one of those post was controversial but I don’t see a reason to mark it as spam.

kind regards

I was sure I checked out the right branch but obviously didn’t. I was still on master. Of course the templates worked just fine once I sucessfully switched to release/v1.13

I’ve copied the following templates:
./admin/monitor.tmpl
./user/dashboard/issues.tmpl
./user/dashboard/milestones.tmpl
./user/dashboard/feeds.tmpl
./repo/branch/list.tmpl
./repo/wiki/pages.tmpl
./repo/wiki/view.tmpl
./repo/wiki/revision.tmpl
./repo/projects/list.tmpl
./repo/issue/milestone_issues.tmpl
./repo/issue/list.tmpl
./repo/issue/view_content/pull.tmpl
./repo/issue/view_content/comments.tmpl
./repo/issue/view_title.tmpl
./repo/issue/milestones.tmpl
./repo/issue/view_content.tmpl
./repo/activity.tmpl
./repo/commit_page.tmpl
./repo/diff/comments.tmpl
./repo/settings/lfs_locks.tmpl
./repo/settings/lfs_file_find.tmpl
./repo/settings/lfs.tmpl
./repo/release/list.tmpl
./repo/commits_list.tmpl
./repo/search.tmpl
./repo/view_list.tmpl
./explore/repo_list.tmpl
./explore/code.tmpl

Then I used this shell command to change all the calls to either TimeSince or TimeSinceUnix on the copied templates:
find . -type f -exec sed -i 's/TimeSince[A-Za-z]*\ \([\$\.A-Za-z0-9]*\)\ [\$\.A-Za-z0-9]*/\1.Format "am 02.01.2006 um 15:04:05 Uhr"/g' {} +

As mentioned before, I didn’t find a way around using a hard coded date format.

This solved the issue for me.

You can actually switch to absolute dates entirely in the browser by adding a bookmarklet with the following function:

javascript:function datestamp(){for (elem of $('span.time-since')) {elem.textContent = elem.attributes["data-content"].value };} datestamp();

You do have to click it every time, but it doesn’t require a code/template change.

Oh, if only I knew. That would have spared me a lot of trouble.

Still, thank you very much for the info.

Would it be possible to make it permanent with a tool like tampermonkey for example?

Hey there, im just replying for future generations:
I solved exaclty this problem by adding a script tag to my header.tmpl file:

<script>
document.addEventListener("DOMContentLoaded", function(event) { 
 var times = document.getElementsByClassName("time-since");
 for (var i = 0; i < times.length; i++) {
   times.item(i).shadowRoot.firstChild.textContent = times.item(i).innerHTML.slice(0, -7);
 }
});
</script>

Maybe this will help others :smiley:

1 Like

Looks like this was just added as a config option recently (after 1.22.0), so it will be available in the next release: Add global setting how timestamps should be rendered by yardenshoham · Pull Request #28657 · go-gitea/gitea · GitHub

1 Like