Skip to content

NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal#11129

Open
superdachuan wants to merge 1 commit intoapache:mainfrom
superdachuan:NIFI-14572
Open

NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal#11129
superdachuan wants to merge 1 commit intoapache:mainfrom
superdachuan:NIFI-14572

Conversation

@superdachuan
Copy link
Copy Markdown

Summary

NIFI-14572

This PR fixes a time offset issue in DateTimeAdapter#unmarshal. The current implementation uses ZonedDateTime, which can lead to ambiguous parsing of time zone abbreviations such as CST, resulting in incorrect offsets. This change aligns the implementation with TimestampAdapter by replacing ZonedDateTime with LocalDateTime and converting it using the system default time zone, avoiding such ambiguity. Although this issue may appear related to NIFI-14581, they are not the same problem and have different root causes: NIFI-14581 is caused by inconsistencies between the time zone ID returned by TimezoneAdapter and the server's default locale, whereas this PR addresses ambiguity in parsing time zone abbreviations. Therefore, this change focuses specifically on fixing the time offset issue in DateTimeAdapter and does not address NIFI-14581.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

Align DateTimeAdapter#unmarshal with TimestampAdapter by replacing
ZonedDateTime with LocalDateTime to avoid timezone ambiguity (e.g., CST)
Copy link
Copy Markdown
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

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

Thanks for working on this issue @superdachuan.

The functional approach looks good, aligning with TimestampAdapter as described.

I noted several recommendations on the test class, which could use some refinement to ensure expected behavior.


@Test
public void testMarshal() throws Exception {
DateTimeAdapter adapter = new DateTimeAdapter();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Adapter instance can be declared once at the class level

@Test
public void testMarshal() throws Exception {
DateTimeAdapter adapter = new DateTimeAdapter();
Date date = Date.from(Instant.parse(TEST_DATE_TIME));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be helpful to avoid the intermediate parsing to an Instant. Instead, using the new Date(long) constructor should provide a more narrow approach to construct a Date with a given value.

public void testMarshal() throws Exception {
DateTimeAdapter adapter = new DateTimeAdapter();
Date date = Date.from(Instant.parse(TEST_DATE_TIME));
assertEquals(date, adapter.unmarshal(adapter.marshal(date)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is testing both marshal and unmarshal in one call. Instead, there should be an expected static final string value, matching the long timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants