Repository: apache/arrow
File: cpp/src/gandiva/precompiled/time.cc (C++)

Code before:
    return (tp.TmMday() == days_in_month[tp.TmMon()]);
  }

  // this is February, check if the day is 28 or 29
  if (tp.TmMday() < 28) {
    return false;
  }

  if (tp.TmMday() == 29) {
    // Feb 29th
    return true;
  }

  // check if year is non-leap year
  return !IsLeapYear(tp.TmYear());
}

FORCE_INLINE
bool is_valid_time(const int hours, const int minutes, const int seconds) {
  return hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60 && seconds >= 0 &&
         seconds < 60;
}

// Normalize sub-seconds value to milliseconds precision (3 digits).
// Truncates if more than 3 digits are provided, pads with zeros if fewer than 3 digits
ARROW_FORCE_INLINE
static inline int32_t normalize_subseconds_to_millis(int32_t subseconds,
                                                     int32_t num_digits) {
  if (num_digits <= 0 || num_digits == 3) {
    // No need to adjust
    return subseconds;
  }
  // Calculate the power of 10 adjustment needed
  int32_t digit_diff = num_digits - 3;
  while (digit_diff > 0) {
    subseconds /= 10;
    digit_diff--;
  }
  while (digit_diff < 0) {
    subseconds *= 10;
    digit_diff++;
  }
  return subseconds;
}

// MONTHS_BETWEEN returns number of months between dates date1 and date2.
// If date1 is later than date2, then the result is positive.
// If date1 is earlier than date2, then the result is negative.
// If date1 and date2 are either the same days of the month or both last days of months,
// then the result is always an integer. Otherwise Oracle Database calculates the
// fractional portion of the result based on a 31-day month and considers the difference

Review comment (suggestion):
I might use the regular 'inline'. I don't see ARROW_FORCE_INLINE really being used anywhere and I don't feel like I know enough that this function should be forced inline.

Code after:
  }

  // this is February, check if the day is 28 or 29
  if (tp.TmMday() < 28) {
    return false;
  }

  if (tp.TmMday() == 29) {
    // Feb 29th
    return true;
  }

  // check if year is non-leap year
  return !IsLeapYear(tp.TmYear());
}

FORCE_INLINE
bool is_valid_time(const int hours, const int minutes, const int seconds) {
  return hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60 && seconds >= 0 &&
         seconds < 60;
}

// Normalize sub-seconds value to milliseconds precision (3 digits).
// Truncates if more than 3 digits are provided, pads with zeros if fewer than 3 digits
static inline int32_t normalize_subseconds_to_millis(int32_t subseconds,
                                                     int32_t num_digits) {
  if (num_digits <= 0 || num_digits == 3) {
    // No need to adjust
    return subseconds;
  }
  // Calculate the power of 10 adjustment needed
  int32_t digit_diff = num_digits - 3;
  while (digit_diff > 0) {
    subseconds /= 10;
    digit_diff--;
  }
  while (digit_diff < 0) {
    subseconds *= 10;
    digit_diff++;
  }
  return subseconds;
}

// MONTHS_BETWEEN returns number of months between dates date1 and date2.
// If date1 is later than date2, then the result is positive.
// If date1 is earlier than date2, then the result is negative.
// If date1 and date2 are either the same days of the month or both last days of months,
// then the result is always an integer. Otherwise Oracle Database calculates the
// fractional portion of the result based on a 31-day month and considers the difference
// in time components date1 and date2
#define MONTHS_BETWEEN(TYPE)                                                        \