Recipe Name:
Convert Joda-Time DateTimeFormat.fullTime()
Description:
Convert Joda-Time DateTimeFormat.fullTime()
Level:
warning
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:datetime-format-fullTime
version: 10
metadata:
  name: Convert Joda-Time DateTimeFormat.fullTime()
  shortDescription: Convert Joda-Time DateTimeFormat.fullTime()
  level: warning
  language: java
  enabled: true
  comment: Searches for org.joda.time.format.DateTimeFormat.fullTime method call and provides fixes to migrate to a java.time equivalent.
  descriptionFile: descriptions/datetimeformat-time.html
  tags: framework specific;java.time;Joda-Time;quality
search:
  methodcall:
    name: fullTime
    type: org.joda.time.format.DateTimeFormat
availableFixes:
- name: Convert to java.time DateTimeFormatter
  actions:
  - rewrite:
      to: java.time.format.DateTimeFormatter.ofLocalizedTime(java.time.format.FormatStyle.FULL)
  - modifyAssignedVariable:
      type: java.time.format.DateTimeFormatter