Search code examples
javaenumsjava-timeperiod

Convert frequency to java.time.Period type


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.


Solution

  • 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.