NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal#11129
NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal#11129superdachuan wants to merge 1 commit intoapache:mainfrom
Conversation
6218af4 to
53f1a63
Compare
Align DateTimeAdapter#unmarshal with TimestampAdapter by replacing ZonedDateTime with LocalDateTime to avoid timezone ambiguity (e.g., CST)
53f1a63 to
d28fbdf
Compare
exceptionfactory
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
This is testing both marshal and unmarshal in one call. Instead, there should be an expected static final string value, matching the long timestamp.
Summary
NIFI-14572
This PR fixes a time offset issue in
DateTimeAdapter#unmarshal. The current implementation usesZonedDateTime, which can lead to ambiguous parsing of time zone abbreviations such asCST, resulting in incorrect offsets. This change aligns the implementation withTimestampAdapterby replacingZonedDateTimewithLocalDateTimeand 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 byTimezoneAdapterand 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 inDateTimeAdapterand does not address NIFI-14581.Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000VerifiedstatusPull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation