Recipe Name:
DateTimeFormatterBuilder Joda-Time toParser/toPrinter is obsolete in java.time
Description:
DateTimeFormatterBuilder Joda-Time toParser/toPrinter is obsolete in java.time
Level:
warning
Language:
  • java
Tags:
  • java.time
  • framework specific
  • Joda-Time
  • quality
Documentation

Migrate from org.joda.time.format.DateTimeFormatterBuilder to Java Time

Joda-Time DateTimeFormatterBuilder migrates to java.time DateTimeFormatterBuilder.

It's the same concept, a builder of the formatter.

Although, most of the methods have a different signature and some even have no equivalent in java.time

Those methods have no equivalent:

  • canBuildFormatter
  • canBuildPrinter
  • canBuildParser

Find some examples below:

Before
    DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
    DateTimeFormatterBuilder appendSecondOfDay = dtfb.appendSecondOfDay(intArg);
After
    java.time.format.DateTimeFormatterBuilder dtfb = new java.time.format.DateTimeFormatterBuilder();
    java.time.format.DateTimeFormatterBuilder appendSecondOfDay = dtfb.appendValue(ChronoField.SECOND_OF_DAY, intArg);
References
Recipe
id: scw:java.time:Joda-Time:datetimeformatterbuilder-toparser-toprinter
version: 10
metadata:
  name: DateTimeFormatterBuilder Joda-Time toParser/toPrinter is obsolete in java.time
  shortDescription: DateTimeFormatterBuilder Joda-Time toParser/toPrinter is obsolete in java.time
  level: warning
  language: java
  enabled: true
  comment: |-
    Methods toPrinter and toParser are obsolete in java.time.
    Please consider to change it.
  descriptionFile: descriptions/datetimeformatterbuilder.html
  tags: java.time;framework specific;Joda-Time;quality
search:
  methodcall:
    anyOf:
    - name: toPrinter
    - name: toParser
    type: java.time.format.DateTimeFormatterBuilder
availableFixes:
- name: Replace Joda-Time toPrinter/toParser with toFormatter()
  actions:
  - rewrite:
      to: '{{{ qualifier }}}.toFormatter()'
  - modifyAssignedVariable:
      type: java.time.format.DateTimeFormatter