Skip to content

fix(log): keep offset seconds in ISO timestamps - #7112

Merged
lvs0075 merged 2 commits into
tronprotocol:release_v4.8.3from
halibobo1205:feature/keep-iso-offset-seconds
Nov 18, 2026
Merged

lvs0075 merged 2 commits into
tronprotocol:release_v4.8.3from
halibobo1205:feature/keep-iso-offset-seconds

Conversation

@halibobo1205

Copy link
Copy Markdown
Collaborator

What does this PR do?

Changes the offset pattern of Time.getIsoTimeString from XXX to XXXXX, so an offset that includes seconds is printed in full, e.g. -00:44:30. Whole-minute offsets print as before (Z, +08:00). Adds TimeTest.

Why are these changes required?

#6950 replaced Joda-Time with Time.getIsoTimeString. XXX prints only hours and minutes, so a historical offset with seconds is truncated and the printed text no longer denotes the logged instant.

Before this change, with Africa/Monrovia as the JVM default zone, epoch 0 was logged as 1969-12-31T23:15:30.000-00:44, which parses back to -30000 ms. Joda-Time printed 1969-12-31T23:15:30.000-00:44:30, and so does this change.

Epoch 0 is the mainnet genesis timestamp. On a node starting from an empty database, DynamicPropertiesStore sets the next maintenance time to it, and applying block 1 makes the first updateNextMaintenanceTime call, which logs it as currentMaintenanceTime.

Only log text is affected. Block times, the maintenance calculation and stored values do not change.

This PR has been tested by:

  • Unit Tests: TimeTest checks that Africa/Monrovia keeps the offset seconds, that UTC (Z) and Asia/Shanghai (+08:00) output is unchanged, and that for every zone in ZoneId.getAvailableZoneIds() the output for 1900-01-01T00:00:00Z, epoch 0 and a 2023 sample with nonzero milliseconds parses back to the same millisecond. Two of the three TimeTest methods fail with XXX. :common:test passes on JDK 17 / arm64.
  • Manual Testing: Compared Joda-Time 2.3 and the JDK formatter across 570 shared zone IDs at three sampled instants on each JDK (JDK 8 / x86_64 and JDK 17 / arm64). With XXXXX, all 1,710 values per JDK round-trip with OffsetDateTime.parse, and the output is byte-identical wherever both libraries resolve the same offset. With XXX, 335 values fail to round-trip on JDK 8 and 332 on JDK 17.

Follow up

The related Logback 1.3 compatibility notes from #6950 (%d zone IDs and S, JVM default zones beyond ±18:00) are documented in #6950's description and are not changed here.

Extra details

XXXXX prints hours, minutes and optional seconds with colons, and Z for a zero offset. It is supported by DateTimeFormatter since JDK 8.

Time.getIsoTimeString used the XXX offset pattern, which drops the
seconds of historical offsets such as Africa/Monrovia's -00:44:30, so
the printed text parsed back to a different instant (30 s off for the
mainnet genesis time 0). Use XXXXX, which prints the seconds only when
the offset has them and keeps +08:00 and Z unchanged, matching
joda-time's DateTime.toString() again.
@317787106

Copy link
Copy Markdown
Collaborator

[NIT] Consider adding a DST-overlap case and representative default-zone IDs outside ZoneId.getAvailableZoneIds(), such as PST and GMT+05:45. The current sweep covers many zones but samples only three instants per zone.

For example, in America/New_York, 2023-11-05T05:30:00Z and 2023-11-05T06:30:00Z should both display 01:30, with offsets -04:00 and -05:00 respectively, and each should round-trip to its original timestamp. These would be useful additions to the regression coverage.

@halibobo1205

Copy link
Copy Markdown
Collaborator Author

[NIT] Consider adding a DST-overlap case and representative default-zone IDs outside ZoneId.getAvailableZoneIds(), such as PST and GMT+05:45. The current sweep covers many zones but samples only three instants per zone.

For example, in America/New_York, 2023-11-05T05:30:00Z and 2023-11-05T06:30:00Z should both display 01:30, with offsets -04:00 and -05:00 respectively, and each should round-trip to its original timestamp. These would be useful additions to the regression coverage.

Thanks, added both in a4c63f9: a DST-overlap case (America/New_York, 2023-11-05T05:30:00Z and 06:30:00Z both display 01:30, at -04:00 and -05:00, and each round-trips), and default zones set through IDs outside ZoneId.getAvailableZoneIds() (PST, GMT+05:45). Test-only; the existing code already gave these outputs, identical to Joda-Time on JDK 8 and 17.

@waynercheung waynercheung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lvs0075
lvs0075 merged commit d520853 into tronprotocol:release_v4.8.3 Nov 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants