class PackedLocalTime {

  public static int truncatedTo(TemporalUnit unit, int packedTime) {
    if (unit == ChronoUnit.NANOS || unit == ChronoUnit.MILLIS) {
      return packedTime;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > SECONDS_PER_DAY) {
      throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }

    int hour = PackedLocalTime.getHour(packedTime);
    int minute = PackedLocalTime.getMinute(packedTime);
    int second = PackedLocalTime.getSecond(packedTime);
    int milli = 0;

    if (unit == ChronoUnit.DAYS) {
      hour = 0;
      minute = 0;
      second = 0;
    } else if (unit == ChronoUnit.HALF_DAYS) {
      if (hour >= 12) {
        hour = 12;
      } else {
        hour = 0;
      }
      minute = 0;
      second = 0;
    } else if (unit == ChronoUnit.HOURS) {
      minute = 0;
      second = 0;
    } else if (unit == ChronoUnit.MINUTES) {
      second = 0;
    }
    return PackedLocalTime.create(hour, minute, second, milli);
  }

}