class PackedLocalDate {

  public static int plusDays(int days, int packedDate) {
    if (days == 0) {
      return packedDate;
    }

    byte d = getDayOfMonth(packedDate);
    byte m = getMonthValue(packedDate);
    short y = getYear(packedDate);

    int dom = days + d;
    if (dom > 0) {
      if (dom <= 28) {
        return pack(y, m, (byte) dom);
      } else if (dom <= 59) { // 59th Jan is 28th Feb, 59th Feb is 31st Mar
        long monthLen = lengthOfMonth(packedDate);
        if (dom <= monthLen) {
          return pack(y, m, (byte) dom);
        } else if (m < 12) {
          return pack(y, (byte) (m + 1), (byte) (dom - monthLen));
        } else {
          YEAR.checkValidValue((long) y + 1);
          return pack((short) (y + 1), (byte) 1, (byte) (dom - monthLen));
        }
      }
    }

    long mjDay = Math.addExact(toEpochDay(packedDate), days);
    return ofEpochDay(mjDay);
  }

}