1

I am trying to construct an org.joda.time.Instant from a LocalDate. Ordinarily it is as simple as;

new org.joda.time.Instant(myDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());

But the project I am working on uses the modernizer-maven-plugin and there is a violation on Prefer java.time.Instant. I am not able to change the API of the class I am attempting to use.

So, my question is how do "Prefer java.time.Instant"?

Thx

Andrew Gaul
  • 2,296
  • 1
  • 12
  • 19
cbm64
  • 1,059
  • 2
  • 12
  • 24
  • And the question is? – Andronicus Feb 25 '20 at 16:47
  • Question updated. – cbm64 Feb 25 '20 at 16:52
  • 1
    If I read the page on [Modernizer Maven Plugin](https://github.com/gaul/modernizer-maven-plugin) correctly, there are some ways to exclude instances of use of legacy API. If you need to use an API that requires a Joda-Time `Instant`, I suggest that this is what you need to do. Your code is fine IMHO. – Ole V.V. Feb 26 '20 at 14:11
  • Yeah, in the end I had to make an exclusion for this code. Apparently there is a method of InstantConverter but I could not figure it out. – cbm64 Feb 26 '20 at 18:35
  • If you need an instance of `org.joda.time.Instant`, I wouldn’t expect that `InstantConverter` would help stop the modernizer complaining. I encourage you to post an answer to your own question to help future readers. – Ole V.V. Feb 27 '20 at 06:23

1 Answers1

0

You can disable specific instances of Modernizer violations via the @SuppressModernizer annotation:

https://github.com/gaul/modernizer-maven-plugin#ignoring-elements

To ignore all instances of a violation, you can add an <exclusions> stanza similar to:

<exclusions>
    <exclusion>org/joda/time/Instant.now:()Lorg/joda/time/Instant;</exclusion>
    <exclusion>org/joda/time/Instant.parse:(Ljava/lang/String;)Lorg/joda/time/Instant;</exclusion>
    <exclusion>org/joda/time/Instant."&lt;init&gt;":(J)V</exclusion>
</exclusions>
Andrew Gaul
  • 2,296
  • 1
  • 12
  • 19