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

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

Joda-Time DateTimeFormatter migrates to java.time DateTimeFormatter.

It's a same concept, an immutable formatter

Before
    DateTimeFormatter dtf = DateTimeFormat.fullDate();
After
    java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
References
Recipe
id: scw:java.time:Joda-Time:datetimeformatter-withzoneutc
version: 10
metadata:
  name: Convert DateTimeFormatter withZoneUTC to java.time equivalent
  shortDescription: Convert DateTimeFormatter withZoneUTC to java.time equivalent
  level: error
  language: java
  enabled: true
  comment: "Searches for a withZoneUTC 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."
  descriptionFile: Java/JodaTimeToJavaTime/DateTimeFormatter/descriptions/datetimeformatter.html
  tags: framework specific;java.time;Joda-Time;quality
search:
  methodcall:
    name: withZoneUTC
    type: java.time.format.DateTimeFormatter
availableFixes:
- name: Rewrite to withZone(ZoneId.of("UTC"))
  actions:
  - rewrite:
      to: '{{{ qualifier }}}.withZone(java.time.ZoneId.of("UTC"))'
  - modifyAssignedVariable:
      type: java.time.format.DateTimeFormatter