Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated joda time #173

Merged
merged 3 commits into from
Jul 1, 2024
Merged

Conversation

AnasNaouchi
Copy link
Contributor

@AnasNaouchi AnasNaouchi commented Jun 25, 2024

Description

Attempt to remove deprecated joda-time library and replace it with java-time.
closes #152

Changes:

  • Replace joda.time.LocalDate with java.time.LocalDate
  • Replace joda.time.YearMonth with java.time.YearMonth
  • Replace joda.time.format.DateTimeFormatter with java.time.format.DateTimeFormatter
  • Replace joda.time.DateTime with java.time.ZonedDateTime
  • Use com.fasterxml.jackson.datatype.jsr310.JavaTimeModule for time serialization and deserialization
  • Use com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer as a LocalDateTime serializer

Backward Compatibility:

To ensure backward compatibility from Joda-time to Java-time:

  • Previous Joda-time string format: 2024-07-01T12:46:25.000Z
  • Current Java-time string format: 2024-07-01T12:46:25Z

Since the milliseconds are missing and ZonedDateTime is a final non-immutable class that can't be extended/overridden as intended to obtain the proper format of the string date, it was decided to leave the formatting up to the integrator to ensure the maximum backward compatible migration.

Joda-time also had some utility functions like getAsText() which is not available in Java-time, so you will receive the year/month/day as an int if you previously accessed them. If you want to format the received ZonedDateTime into the same string format as that of Joda-time, you can use the following formatter:

private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");

If your integration depends heavily on this formatting, you can create a utility class that would allow you to parse the date to the desired format and still access the zonedDateTime variable:

public static class CustomZonedDateTime {

    private final ZonedDateTime zonedDateTime;
    private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");

    public CustomZonedDateTime(ZonedDateTime zonedDateTime) {
        this.zonedDateTime = zonedDateTime;
    }

    @Override
    public String toString() {
        return zonedDateTime.format(formatter);
    }

    public ZonedDateTime getZonedDateTime() {
        return zonedDateTime;
    }
}

And use it like this:

final formattedString = new CustomZonedDateTime(createdCharge.createdAt).toString(); // gives you the formatted string, ex: 2024-06-24T17:07:53.717Z
final zonedTime = createdCharge.createdAt.getZonedDateTime();

@AnasNaouchi AnasNaouchi merged commit d317599 into master Jul 1, 2024
1 check passed
@AnasNaouchi AnasNaouchi deleted the remove_deprecated_joda_time branch July 1, 2024 03:01
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.

When are you planning to migrate from joda-time to java.time?
3 participants