arduino-ide icon indicating copy to clipboard operation
arduino-ide copied to clipboard

Leading zeros are stripped from Serial Monitor timestamps

Open per1234 opened this issue 3 years ago • 3 comments

Describe the problem

🐛 The timestamps produced by the Serial Monitor have a non-standard format resulting from stripping the leading zeros from the hours and minutes.

🐛 This is not even done consistently as the leading zeros are preserved for seconds.

To Reproduce

Steps to reproduce the behavior:

  1. Upload a sketch to an Arduino board that periodically prints to the serial port. For example:
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      Serial.println("hello");
      delay(1000);
    }
    
  2. Select Tools > Serial Monitor from the Arduino IDE menus.
  3. Click the :clock10: icon ("Toggle Timestamp") that is near the top right corner of the output panel
  4. Wait for a time that contains a second less than 10.
  5. Look at the Serial Monitor output pane. 🙂 Note that the leading zero on the second component of the time has not been removed.
  6. Wait for a time that contains a minute less than 10.
  7. Look at the Serial Monitor output pane. 🐛 Note that the leading zero on the minute component of the time has been removed.
  8. Wait for a time that contains an hour less than 10.
  9. Look at the Serial Monitor output pane. 🐛 Note that the leading zero on the hour component of the time has been removed.
23:59:58.610 -> hello
23:59:59.609 -> hello
0:0:00.620 -> hello
0:0:01.618 -> hello
0:0:02.630 -> hello

Expected behavior

Serial Monitor timestamps to be formatted the same as they were in the classic Arduino IDE: hh:mm:ss.sss

00:05:02.590 -> hello

Arduino IDE version

Original report

2.0.0-beta.12-nightly.20211028

Last verified with

2.0.0-rc9-snapshot-5087ff0

Operating system

Windows 10

Additional context

Originally reported at:

  • https://forum.arduino.cc/t/serial-monitor-changes-time-stamp-format/870115
  • https://github.com/arduino/arduino-ide/issues/391#issuecomment-877585479

per1234 avatar Oct 28 '21 06:10 per1234

It is still exists in 2.0.0-rc4.

image

mklemarczyk avatar Mar 06 '22 17:03 mklemarczyk

@per1234 do we still have this issue?

ubidefeo avatar Jul 25 '22 14:07 ubidefeo

@ubidefeo yes:

Leading zeros are still stripped from hours: image

Leading zeros are still stripped from minutes:

image

21:9:29.101 -> hello
21:9:30.088 -> hello
21:9:31.104 -> hello

per1234 avatar Jul 25 '22 14:07 per1234

I think the relevant code affecting this is given here https://github.com/arduino/arduino-ide/blob/df8658eff9d1758239923c740357ed6b33b7397e/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx#L110-L113

Can I go ahead and submit a PR changing it to

  const timestamp =
    (data.timestamp &&
      `${dateFormat(data.lines[index].timestamp, 'HH:MM:ss.l')} -> `) ||
    '';

nmzaheer avatar Sep 08 '22 03:09 nmzaheer

Can I go ahead and submit a PR

Hi @nmzaheer. Please do. I'll be happy to review it.

per1234 avatar Sep 08 '22 03:09 per1234

@per1234 I've tested it on Ubuntu through WSL with my Uno board and it works.

nmzaheer avatar Sep 08 '22 04:09 nmzaheer