Skip to content

Conversation

@turcsanyip
Copy link
Contributor

@turcsanyip turcsanyip commented Dec 8, 2025

Summary

NIFI-15308

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 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

Copy link
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 addressing this issue @turcsanyip. The implementation in the Field Converter looks good, following the same basic strategy as the converter for LocalDateTime.

Although the TimeZone.setDefault() approach for testing is used in some other modules, it should be possible to avoid that and instead compare expected values.

The ObjectTimestampFieldConverterTest has a getDateTimeZoneOffset method that builds a string with a specific offset based on the current system default timezone, which is one way to evaluate the conversion, without having to call TimeZone.setOffset(). I recommend looking at that approach as opposed to changing the default TimeZone in the test method.

@turcsanyip
Copy link
Contributor Author

Thanks for your feedback @exceptionfactory. I updated the tests to avoid setting the default time zone at the JVM level.

Actually, I was focusing on the use case where the same input data is processed in environments with different time zone settings. But the issue can also be tested by using the same runtime time zone with different input data offsets. The main point is that the JVM’s system time zone needs to be different from the input data’s offset. It does not matter in what way.

I added several different time zone offsets to the tests in order to cover various cases (not only system default and UTC that can overlap and might not reveal the current issue).

Copy link
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 the update @turcsanyip. The tests look better without the TimeZone changes. However, the construction of the expected value is still a bit difficult to follow. In past experience, I have found this to be important when reviewing conversion code and associated expectations.

Comment on lines 46 to 48
final LocalTime expected = ZonedDateTime.of(LocalDate.EPOCH, LocalTime.parse(timeString, DateTimeFormatter.ofPattern(TIME_WITH_OFFSET_PATTERN)), ZoneId.of(offset))
.withZoneSameInstant(ZoneId.systemDefault())
.toLocalTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

The levels of nesting make this declaration rather hard to follow.

On closer analysis, I think a different approach is needed.

The parsing and conversion from LocalTime to ZonedDateTime and back to LocalTime effectively do something similar to what the FieldConverter itself is doing.

The challenge is LocalTime is different based on where it is running. However, the main goal of the comparison should be that the FieldConverter shifts the hours forward or backward, based on the relative offset. The issue is that the number of hours is different based on the JVM system default zone. That's the reason for limiting the test to the offset of the system default zone, versus attempting to test other offsets.

With that background, it would help break up the declaration of each variable, as opposed to nesting the parsing and construction of different values. That should make it somewhat easier to understand how the expected value is being constructed.

I can take a closer look at providing an alternative if that would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Time-related code is not easy to read, and I actually spent a lot of time getting familiar with the existing code as well. I created an updated version in which the result of each step is assigned to variables with explicit, descriptive names. I’m wondering what you think of it.

Copy link
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 the updates @turcsanyip, I pushed a minor update to the test classes, adjusting the ordering, naming, and breaking out the ZoneOffset variable from the input string. If those changes look good to you, I will proceed with merging.

@turcsanyip
Copy link
Contributor Author

@exceptionfactory The code looks good. Please go ahead with merging.
The Windows job failed but looks unrelated. I restarted it to be sure.

Copy link
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 again @turcsanyip! +1 merging

@exceptionfactory exceptionfactory merged commit edb81fe into apache:main Dec 16, 2025
9 of 11 checks passed
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