2

I am getting frequency in form of enum i.e. [ DAILY, WEEKLY, BI-WEEKLY, MONTHLY, BI-MONTHLY, ANNUALLY] and we need to convert that enum to frequency of java.time.Period type then how to convert BI-WEEKLY & BI-MONTHLY into java.time.Period.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Abhinay Kumar
  • 101
  • 1
  • 8
  • 1
    so you are able to convert DAILY, WEEKLY, MONTHLY and ANNUALLY, but not BI-WEEKLY and BI-MONTHLY ? – Luca Tampellini Aug 16 '18 at 14:20
  • No i am not able to convert any of enum. But i want to convert and I mention these two because is on High priority. – Abhinay Kumar Aug 16 '18 at 14:21
  • `if (DAILY) return Period.ofDays(1)`? for bi-weekly/bi-monthly you have to find a compromise because a period is of fixed length in whole days or weeks and bi-weekly can't be represented exactly and bi-monthly depends on the length of the month. Either this works for you or don't use `Period` – zapl Aug 16 '18 at 14:22
  • 1
    @AbhinayKumar please edit your question and add the code of your enum. Additionally: can you edit the code of that enum? – Luca Tampellini Aug 16 '18 at 14:25

2 Answers2

3

You can use Period.ofMonths(2) and Period.ofWeeks(2) for bi-monthly and bi-weekly respectively.

Codebender
  • 14,221
  • 7
  • 48
  • 85
3

We should just be able to put static values in the enum...Period.ofDays(1) = daily, Period.ofWeeks(2) = bi-weekly, etc. Duration unit = months, duration = 5(assume), then Period.ofMonths(duration).

Thanks.

AKA
  • 618
  • 1
  • 5
  • 12