1

I am creating a Green Pass app and I need some info. I use Kotlin with this code:

val expirationTime = Instant.ofEpochSecond (map [CwtHeaderKeys.EXPIRATION.asCBOR ()]. AsInt64 ())
verificationResult.isNotExpired = expirationTime.isAfter (Instant.now ())

I should check between the certificate date and today's date, if it exceeds 45 days it opens a new activity for me.

1
  • 2
    Couldn't you just calculate the difference of your dates and check if the difference is greater than 3.888.000 (45 days in seconds) and if it is greater open the new activity. Commented Aug 5, 2021 at 10:52

2 Answers 2

1

You can use java.time.temporal.ChronoUnit

Example to find number of days between two dates:

ChronoUnit.DAYS.between(date1, date2)

You can use the same mechanisem for other time units:

ChronoUnit.MONTHS.between(date1, date2)

Get the result and check if its greater then 45.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use java.time.Duration

val days = Duration.between(expirationTime, Instant.now()).toDays()
if (days > 45) {
   // your actions
}

4 Comments

@GiuseppeEDP yes
Ok, i have a problem. If i put code on DefaultCborService not import element i.imgur.com/WyW4Fnk.png
@GiuseppeEDP i didn't understand anything from your picture. Try putting a better example in your original Question
I would need a popup warning me when the date exceeds 45 days, the code is this: val issuedAt = Instant.ofEpochSecond(map[CwtHeaderKeys.ISSUED_AT.asCBOR()].AsInt64()) verificationResult.isIssuedTimeCorrect = issuedAt.isBefore(Instant.now())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.