Is it possible that a duration is formatted like following.
8 hours will be considered as a day.
5 days considered as a week
so 28800*1000 seconds duration will give output as 1d on periodformatting
Is it possible that a duration is formatted like following.
8 hours will be considered as a day.
5 days considered as a week
so 28800*1000 seconds duration will give output as 1d on periodformatting
I’m afraid that it can’t be reduced to a question of formatting. You will have to do some math yourself.
Period p = Period.hours(61);
int days = p.toStandardHours().getHours() / HOURS_PER_DAY;
Period remaining = p.minusHours(days * HOURS_PER_DAY);
int weeks = days / DAYS_PER_WEEK;
days -= weeks * DAYS_PER_WEEK;
System.out.println("" + weeks + " weeks " + days + " days " + remaining);
Output:
1 weeks 2 days PT5H
As you may have guessed I am assuming these constants:
private static final int HOURS_PER_DAY = 8;
private static final int DAYS_PER_WEEK = 5;
I considered converting back to a new Period
so that one might apply a PeriodFormatter
, but I really don’t think it’s a good idea. A Period
is meant for a period of physical time, not work time or the like.