0

I'm using the AccountingDate implemented into this project.

public final class AccountingDate extends AbstractDate implements ChronoLocalDate, Serializable {}

Do you know a way to convert an AccountingDate to Instant or LocalDate?

Safari
  • 11,437
  • 24
  • 91
  • 191

2 Answers2

3

AccountingDate implements ChronoLocalDate, which supports all date based ChronoFields, so it supports ChronoFields.EPOCH_DAY, so LocalDate.from works:

LocalDate.from(accountingDate)

To convert a date to an Instant, you need two more pieces of information:

  • time
  • zone offset

If we assume the time is midnight, and the zone offset being UTC, we can do:

accountingDate.atTime(LocalTime.MIDNIGHT).atZone(ZoneOffset.UTC).toInstant()
Sweeper
  • 213,210
  • 22
  • 193
  • 313
1

Since it's a chrono date, you need to go through the epoch days

This would be e.g. like:

AccountingDate accountingDate = ...
LocalDate date = LocalDate.ofEpochDay(accountingDate.toEpochDay())
Indivon
  • 1,784
  • 2
  • 17
  • 32