Пример #1
0
moment_t
THX_moment_new(pTHX_ IV Y, IV M, IV D, IV h, IV m, IV s, IV ns, IV offset) {
    moment_t r;
    int64_t rdn, sod;

    THX_check_year(aTHX_ Y);
    THX_check_month(aTHX_ M);
    if (D < 1 || D > 28) {
        int dim = dt_days_in_month(Y, M);
        if (D < 1 || D > dim)
            croak("Parameter 'day' is out of the range [1, %d]", dim);
    }
    THX_check_hour(aTHX_ h);
    THX_check_minute(aTHX_ m);
    THX_check_second(aTHX_ s);
    THX_check_nanosecond(aTHX_ ns);
    THX_check_offset(aTHX_ offset);

    rdn = dt_rdn(dt_from_ymd(Y, M, D));
    sod = h * 3600 + m * 60 + s;
    r.sec    = rdn * SECS_PER_DAY + sod;
    r.nsec   = ns;
    r.offset = offset;
    return r;
}
Пример #2
0
static moment_t
THX_moment_with_day_of_month(pTHX_ const moment_t *mt, IV v) {
    int y, m;

    dt_to_ymd(moment_local_dt(mt), &y, &m, NULL);
    if (v < 1 || v > 28) {
        int dim = dt_days_in_month(y, m);
        if (v < 1 || v > dim)
            croak("Parameter 'day' is out of the range [1, %d]", dim);
    }
    return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, m, (int)v));
}
Пример #3
0
static moment_t
THX_moment_with_month(pTHX_ const moment_t *mt, IV v) {
    int y, m, d;

    THX_check_month(aTHX_ v);
    dt_to_ymd(moment_local_dt(mt), &y, NULL, &d);
    m = (int)v;
    if (d > 28) {
        int dim = dt_days_in_month(y, m);
        if (d > dim)
            d = dim;
    }
    return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, m, d));
}
Пример #4
0
bool
dt_valid_ymd(int y, int m, int d) {
    return ((m >= 1 && m <= 12) && 
            (d >= 1 && (d <= 28 || d <= dt_days_in_month(y, m))));
}
Пример #5
0
int
dt_length_of_month(dt_t dt) {
    int y, m;
    dt_to_ymd(dt, &y, &m, NULL);
    return dt_days_in_month(y, m);
}