arduino-ide
arduino-ide copied to clipboard
Leading zeros are stripped from Serial Monitor timestamps
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:
- 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); }
- Select Tools > Serial Monitor from the Arduino IDE menus.
- Click the :clock10: icon ("Toggle Timestamp") that is near the top right corner of the output panel
- Wait for a time that contains a second less than 10.
- Look at the Serial Monitor output pane. 🙂 Note that the leading zero on the second component of the time has not been removed.
- Wait for a time that contains a minute less than 10.
- Look at the Serial Monitor output pane. 🐛 Note that the leading zero on the minute component of the time has been removed.
- Wait for a time that contains an hour less than 10.
- 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
It is still exists in 2.0.0-rc4.
@per1234 do we still have this issue?
@ubidefeo yes:
Leading zeros are still stripped from hours:
Leading zeros are still stripped from minutes:
21:9:29.101 -> hello
21:9:30.088 -> hello
21:9:31.104 -> hello
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')} -> `) ||
'';
Can I go ahead and submit a PR
Hi @nmzaheer. Please do. I'll be happy to review it.
@per1234 I've tested it on Ubuntu through WSL with my Uno board and it works.