0

Is it possible that a duration is formatted like following.

  1. 8 hours will be considered as a day.

  2. 5 days considered as a week

so 28800*1000 seconds duration will give output as 1d on periodformatting

GJoshi
  • 141
  • 2
  • 9

1 Answers1

1

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.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161