Recipe Name:
Constructor argument (ReadableInstant) needs to be migrated to java.time before Constructor Migration can occur
Description:
Constructor argument (ReadableInstant) needs to be migrated to java.time before Constructor Migration can occur
Level:
info
Language:
  • java
Tags:
  • framework specific
  • java.time
  • Joda-Time
  • quality
Documentation

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

Joda-Time DateTime migrates to java.time ZonedDateTime or OffsetDateTime.

ZonedDateTime is the same concept, date and time with time-zone.

OffsetDateTime is a new concept, date and time with offset from UTC.

Before
    DateTime dateTime = new DateTime();
    int monthOfYear = dateTime.getMonthOfYear();
After
    ZonedDateTime dateTime = ZonedDateTime.now();
    int monthOfYear = dateTime.getMonthValue();
References
Recipe
id: scw:java.time:Joda-Time:DateTime-constructor-ReadableInstant
version: 10
metadata:
  name: Constructor argument (ReadableInstant) needs to be migrated to java.time before Constructor Migration can occur
  shortDescription: Constructor argument (ReadableInstant) needs to be migrated to java.time before Constructor Migration can occur
  level: info
  language: java
  enabled: true
  comment: |
    Searches for an instance creation of org.joda.time.DateTime which uses a ReadableInstant as an argument to the constructor.

    This recipe is an information only recipe, to guide the user to migrate the ReadableInstant to a java.time equivalent first.
    After migrating the ReadableInstant argument, this recipe will no longer match, and new recipes that provide the migration fixes will be able to match, depending on which java.time class the ReadableInstant was migrated to (ZonedDateTime, OffsetDateTime or Instant).
  descriptionFile: descriptions/datetime.html
  tags: framework specific;java.time;Joda-Time;quality
search:
  instanceCreation:
    args:
      1:
        type: org.joda.time.ReadableInstant
    anyOf:
    - argCount: 1
    - argCount: 2
    type: org.joda.time.DateTime
availableFixes: []