steveseguin / social_stream

Consolidate your live social messaging streams and much more
http://socialstream.ninja/
GNU General Public License v3.0
516 stars 74 forks source link

24h clock is showing 24:30 at 00:30 #254

Open JdotCarver opened 1 week ago

JdotCarver commented 1 week ago

Pretty simple. Activating the 24h option in the extension (shows 24:32 instead of 00:32 for example).

steveseguin commented 1 week ago

I need more information.

image

The code for the time looks correct to me, but either I'm looking in the wrong spot or there is an issue I'm missing.

Is this on the dock.html? Can you please provide details on version, browser, page, url parameters used, etc.

Maybe a screen shot?

JdotCarver commented 1 week ago

Issue is present on 1.77.2 : L5qUnEi6gs

This is how it looks like : obs64_TVsuAdN9wj obs64_ZteGx9JOhU

This happens on OBS browser source, and what they call "custom browser docks"

steveseguin commented 1 week ago

Thank you. very strange. I'll do some testing. thank you

JdotCarver commented 1 week ago

Thank you. 🙏

If you need any additional info, feel free to ask.

LeMyst commented 1 week ago
var clock24hr = false

var date = new Date('2024-06-27T00:40:00Z');
var timeArrived = date.toLocaleString('en-US', { hourCycle: (clock24hr ? 'h23' : 'h12'), hour: "numeric", minute: "numeric" })
console.log(timeArrived)

clock24hr = true

timeArrived = date.toLocaleString('en-US', { hourCycle: (clock24hr ? 'h23' : 'h12'), hour: "numeric", minute: "numeric" })
console.log(timeArrived)

Output:

12:40 AM
00:40

I don't know if it's something correct for your project.

steveseguin commented 1 week ago

Thank you. I submitted new code already, which is more clearly defined and doesn't rely on toLocaleString

var timeArrived = "";
if (datestamp) {
    var date = new Date();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    minutes = minutes < 10 ? "0" + minutes : minutes;

    if (!clock24hr) {
        var ampm = hours >= 12 ? "PM" : "AM";
        hours = hours % 12;
        hours = hours ? hours : 12; // the hour '0' should be '12'
        timeArrived = `${hours}:${minutes} ${ampm}`;

        if (compactmode) {
            timeArrived = timeArrived.split(" ")[0]; // Removes AM/PM part
        }
    } else {
        hours = hours < 10 ? "0" + hours : hours;
        timeArrived = `${hours}:${minutes}`;
    }

    timeArrived = "<div class='time-arrived'>" + timeArrived + "</div>";
}

I'm probably using it wrong.

steveseguin commented 6 days ago
var clock24hr = false

var date = new Date('2024-06-27T00:40:00Z');
var timeArrived = date.toLocaleString('en-US', { hourCycle: (clock24hr ? 'h23' : 'h12'), hour: "numeric", minute: "numeric" })
console.log(timeArrived)

clock24hr = true

timeArrived = date.toLocaleString('en-US', { hourCycle: (clock24hr ? 'h23' : 'h12'), hour: "numeric", minute: "numeric" })
console.log(timeArrived)

Output:

12:40 AM
00:40

I don't know if it's something correct for your project.

h11 - 12-hour clock with 0-11, using AM/PM. h12 - 12-hour clock with 1-12, using AM/PM. h23 - 24-hour clock with 0-23. h24 - 24-hour clock with 1-24.

I suppose I was using h24 mode unexpectedly? not sure.