Recipe Name:
Rewrite appendFractionOfSecond to appendFraction
Description:
Rewrite appendFractionOfSecond to appendFraction
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-appendfractionsecond
version: 10
metadata:
  name: Rewrite appendFractionOfSecond to appendFraction
  shortDescription: Rewrite appendFractionOfSecond to appendFraction
  level: warning
  language: java
  enabled: true
  comment: |
    Searches for a append* method called and provides fixes to migrate to a java.time equivalent.
    This recipe is designed to match on broken code. This method originally was called by joda DateTimeFormatterBuilder type,
    however this object type should first be migrated to java.time.format.DateTimeFormatterBuilder using the other migration recipes.
    This recipe will then match on the broken code, and the fixes in this recipe will allow the completion of the migration.
  descriptionFile: descriptions/datetimeformatterbuilder.html
  tags: java.time;framework specific;Joda-Time;quality
search:
  methodcall:
    argCount: 2
    name: appendFractionOfSecond
    type: java.time.format.DateTimeFormatterBuilder
availableFixes:
- name: Rewrite using appendFraction(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint)
  actions:
  - rewrite:
      to: '{{{ qualifier }}}.appendFraction(java.time.temporal.ChronoField.MILLI_OF_SECOND, {{{ arguments }}}, false)'
  - modifyAssignedVariable:
      type: java.time.format.DateTimeFormatterBuilder