question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTimeTickUnits: The X-axis of `DateTime` mixture 24-hour and 12-hour notation.

See original GitHub issue

ScottPlot Version: 4.1.58.0

Operating System: Windows10

Application Type: WinForms

Question: The X-axis of DateTime mixture 24-hour and 12-hour notation.

Zoom in on a graph displaying DateTime data on the X-axis with the mouse wheel or right-click.

In this case, the 24-hour and 12-hour displays show different times, depending on whether they zoom to the nearest second or include milliseconds.

It appears that 24-hour notation is used for zooms that display up to seconds, and 12-hour notation is used for zooms that also display milliseconds.

Is this as expected?

pattern Actual output comment
(A) Zooms that display up to seconds. 1985/09/23
23:59:59
As expected.
(B) Zooms that also display milliseconds. 1985/09/23
11:59:59.5
The time format expects 23:59:59.5.

Maybe HH is correct in (B) instead of hh?

Animation

The reproduced code is as follows: <div>
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        ExecuteRecipe(formsPlot1.Plot);
    }

    private void ExecuteRecipe(Plot plt)
    {
        // original source: https://github.com/ScottPlot/ScottPlot/blob/07ab190973cbf8697ff8bdc98b4e6475ce40ea03/src/ScottPlot4/ScottPlot.Cookbook/Recipes/Axis.cs#L208-L222

        // create data sample data
        var myDates = new DateTime[1000]; // Change: 100 --> 1000
        for (var i = 0; i < myDates.Length; i++)
            myDates[i] = new DateTime(1985, 9, 24).AddMinutes(10 * i); // Change: .AddDays(7 * i) --> .AddMinutes(10 * i)

        // Convert DateTime[] to double[] before plotting
        var xs = myDates.Select(x => x.ToOADate()).ToArray();
        var ys = DataGen.RandomWalk(myDates.Length);
        plt.AddScatter(xs, ys);

        // Then tell the axis to display tick labels using a time format
        plt.XAxis.DateTimeFormat(true);
    }
}
</div>

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bclehmanncommented, Sep 24, 2022

I actually have a better option, we can check if the configured locale uses 24 hour time and swap out hh for HH. Otherwise we leave it as is. It’s a hack, but it’s not as breaking (or broken) a breaking change.

0reactions
MareMarecommented, Sep 24, 2022

Sorry for the late reply.

However here the user would still have to override 12 DateTimeUnit classes just to change some formatting rules, which seems excessive.

Yeah, you are right. I was a bit shallow in my thinking.

So I think for the timebeing I’m just going to create a PR that enforces 24-hour clock, and then at some point we might circle back on letting people write their times differently.

Thank you for creating the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert 24 hour clock to 12 hour clock in dataframe ...
On the x-axis I want to just have time on the 12-hour clock (so using the graph ... import datetime as dt d...
Read more >
How to convert character date time if time mixed between ...
I don't think that is necessary though. The 12-hour solution seems to be working just fine, but the 24-hour format must still be...
Read more >
Time cannot be set to 24 hour format in Continuous X Axis
Yes by using text format time value, we can show them in 12h or 24h as we want. But in this case the...
Read more >
Time question in 12 hour format in feature report
In my survey I have work start and work end Time questions. In my feature report, they display in a 24 hour format....
Read more >
Time formatting for charts | Looker
Format Type Description Use This Expression Time Milliseconds as a decimal number, i.e. 000 to 999 %L Time Second as a two‑digit number, i.e. 00...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found