2

I'm using org.joda.time.Period to calculate the frequency of an event happening. That frequency can be yearly, quarterly, monthly, weekly, daily, etc. I would like to know if there is a way to calculate how many times my period fits into a year. For example, for a monthly frequency (P1M), the value would be 12. For a weekly one (P1W), it would be 52. For a quarterly one (P3M), that value would be 4.

None of the methods from org.joda.time.Period seem to be useful for this case. Also, the answer needs to have an acceptable level of accuracy. For example, it would NOT be acceptable to turn the period into days and then calculate the yearly value by dividing 365 to the number of days.

Sorin
  • 31
  • 2
  • 4
  • What *is* and acceptable level of accuracy then? For some years a period of P1D fits 365 times in a year, for some, 366 times. A P1W fits 52 times in a year, but you have a 1 or 2 days left over. What about P5M? What would be the answer then? 2 times? Why is it not acceptable to turn the period into days and divide the year length by that? – Adam Michalik Apr 11 '19 at 08:12
  • That’s certainly doable if you can specify precisely what you want. Writing so because I think you will have a lot of corner cases where you will need to decide what the outcome should be. For just one example, a period of 61 days would fit 6 times into a leap year but in most years only 5 full times. – Ole V.V. Apr 16 '19 at 09:25

0 Answers0