Skip to content

Force format to absolute iso8601 #293

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

Open
ericslaw opened this issue Oct 2, 2024 · 2 comments
Open

Force format to absolute iso8601 #293

ericslaw opened this issue Oct 2, 2024 · 2 comments

Comments

@ericslaw
Copy link

ericslaw commented Oct 2, 2024

This code runs on github.com and displays timestamps in relative formatting...
but I really NEVER want to see timestamps in relative form.

I'd so much rather that 'last week' show up as '2024-09-26 19:05:24' or anything similar to iso8601.

Perhaps this just needs a new format string (for non-duration timestamps) of 'iso8601' ?

I can convince github pages to reveal an absolute timestamp with the following snippet pasted into the console.

document.querySelectorAll('relative-time[datetime]')
    .forEach( item => {
        item.setAttribute('format','datetime')
        item.setAttribute('formatStyle','long')
        item.setAttribute('precision','minute')
    });

... but I get 'Thu, Sep 26' which is way too short.

I can use this snippet to update the title to show what I want but I still have to hover

document.querySelectorAll('relative-time[datetime]')
    .forEach( item =>
        item.setAttribute(
            "title",
            new Date(
                Math.round(
                    Date.parse( item.getAttribute("datetime") )
                    / 60000 ) * 60000
            )
                .toISOString()
                .replace(/T/," ")
                .replace(/[.].*/,"")
                +" UTC"
        )
    )

perhaps I should be looking to convince Intl.DateTimeFormat with a Locale that emits iso8601 instead?

@liath
Copy link

liath commented Mar 19, 2025

Building on your idea:

document.querySelectorAll('relative-time[datetime]').forEach(ele => { ele.outerHTML = (new Date(ele.getAttribute('datetime'))).toISOString() });

@keithamus
Copy link
Contributor

If you want to disable the behaviour you should be able to call customElements.define('relative-time', class extends HTMLElement{}) before GitHub's JS kicks in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants