Recipe Name:
Migrate new DateTime() to java.time
Description:
Migrate new DateTime() to java.time
Level:
warning
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.
BeforeDateTime 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-empty version: 10 metadata: name: Migrate new DateTime() to java.time shortDescription: Migrate new DateTime() to java.time level: warning language: java enabled: true comment: | Searches for an instance creation of org.joda.time.DateTime and provides fixes to migrate to a java.time equivalent. This recipe will cause broken code as part of an overall number of steps to perform a migration of Joda-Time to java.time. After migrating this instance creation to the java.time equivalent, subsequent method calls and usages of the instance may become invalid. Further Sensei recipes are available to help resolve many of these invalid usages. descriptionFile: descriptions/datetime.html tags: framework specific;java.time;Joda-Time;quality search: instanceCreation: argCount: 0 type: org.joda.time.DateTime availableFixes: - name: Migrate to java.time.ZonedDateTime.now() actions: - modifyAssignedVariable: type: java.time.ZonedDateTime - rewrite: to: java.time.ZonedDateTime.now() - name: Migrate to java.time.OffsetDateTime.now() actions: - modifyAssignedVariable: type: java.time.OffsetDateTime - rewrite: to: java.time.OffsetDateTime.now()