Recipe Name:
Convert parseLocalTime to java.time version
Description:
Convert parseLocalTime to java.time version
Level:
error
Language:
  • java
Tags:
  • framework specific
  • java.time
  • Joda-Time
  • quality
Documentation

Migrate from org.joda.time.DateTimeFormat to Java Time

Joda-Time DateTimeFormat and ISODateTimeFormat migrate to java.time DateTimeFormatter.

Joda-time and java.time use same concept for DateTimeFormatters

There are 4 predefined types of time, they are:

  • Full
  • Long
  • Medium
  • Short

For parsing, none method has equivalent in java.time.

Examples

Before
    DateTimeFormatter joda = DateTimeFormat.fullTime();
    String jodaResult = joda.print(long);
After
    java.time.format.DateTimeFormatter javaFormatter = java.time.format.DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL);
    String javaResult = javaFormatter.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(long), ZoneId.systemDefault()));
References
Recipe
id: scw:java.time:Joda-Time:datetimeformatter-parseLocalTime
version: 10
metadata:
  name: Convert parseLocalTime to java.time version
  shortDescription: Convert parseLocalTime to java.time version
  level: error
  language: java
  enabled: true
  comment: "Searches for a parseLocalTime method called and provides fixes to migrate to a java.time equivalent.\n\nThis recipe is designed to match on broken code. This method originally was called by org.joda.time.format.DateTimeFormatter type, \nhowever this object type should first be migrated to java.time.format.DateTimeFormatter using the other migration recipes.\nThis recipe will then match on the broken code, and the fixes in this recipe will allow the completion of the migration.\nBe aware if you are using the correct pattern for this formatter."
  descriptionFile: Java/JodaTimeToJavaTime/DateTimeFormat/descriptions/datetimeformat-time.html
  tags: framework specific;java.time;Joda-Time;quality
search:
  methodcall:
    name: parseLocalTime
    type: java.time.format.DateTimeFormatter
availableFixes:
- name: Rewrite parseLocalTime to java.time equivalent
  actions:
  - rewrite:
      to: java.time.LocalTime.parse({{{ arguments}}}, {{{ qualifier }}})
  - modifyAssignedVariable:
      type: java.time.LocalTime