yuyu1025 opened a new pull request, #1385:
URL: https://github.com/apache/commons-lang/pull/1385
#### **Background and Motivation**
With the widespread adoption of Java 8+, the project has gradually moved
from the traditional `java.util.Date` to modern date-time APIs (such as
`LocalDateTime`), but a large amount of existing code still relies on `Date`.
To reduce migration costs and improve development efficiency, it is necessary
to provide officially supported conversion tools in Apache Commons Lang to
avoid developers repeating the implementation of underlying logic.
#### **Core Change Content**
1. **New Conversion Methods**
- `toLocalDateTime(Date date)`:Uses the system's default time zone,
simplifying common conversion scenarios.
- `toLocalDateTime(Date date, TimeZone tz)`:Explicitly specifies the time
zone, meeting internationalization requirements (e.g., converting UTC time to
local time in a specific time zone).
- Implementation principle: Converts using `Instant` and `ZoneId`,
ensuring time zone accuracy (including daylight saving time, handling of
extreme time zones).
2. **Improve test coverage**
- Covers scenarios such as default time zones, specified time zones, null
value validation, daylight saving time (e.g., New York in the United States),
extreme time zones (e.g., Kiribati with UTC+14) to ensure code robustness.
#### **Value Added**
- **Smooth Migration**: Allows developers to gradually introduce
`LocalDateTime` without modifying the existing `Date` interface, reducing
refactoring risks.
- **Consistency and Reliability**: Provides Apache's official conversion
logic, avoiding potential bugs in third-party implementations, and enhancing
project stability.
- **Feature Extension**: Enhance `DateUtils` modern support to adapt to Java
8+ ecosystem, responding to the community's need for bridging new and old APIs.
#### **Compatibility Note**
- No breaking changes, new methods are independent extensions, do not affect
existing `DateUtils` functionality.
- Depends on Java 8+ (consistent with Apache Commons Lang 3.18+).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]