static moment_t THX_moment_with_day_of_quarter(pTHX_ const moment_t *mt, IV v) { int y, q; dt_to_yqd(moment_local_dt(mt), &y, &q, NULL); if (v < 1 || v > 90) { int diq = dt_days_in_quarter(y, q); if (v < 1 || v > diq) croak("Parameter 'day' is out of the range [1, %d]", diq); } return THX_moment_with_local_dt(aTHX_ mt, dt_from_yqd(y, q, (int)v)); }
bool dt_valid_yqd(int y, int q, int d) { return ((q >= 1 && q <= 4) && (d >= 1 && (d <= 90 || d <= dt_days_in_quarter(y, q)))); }
int dt_length_of_quarter(dt_t dt) { int y, q; dt_to_yqd(dt, &y, &q, NULL); return dt_days_in_quarter(y, q); }