dt_status_t dt_representation_to_tm()

in src/dt.c [463:494]


dt_status_t dt_representation_to_tm(const dt_representation_t *representation, struct tm *tm)
{
    int dow = 0;
    int doy = 0;
    dt_status_t status = DT_UNKNOWN_ERROR;

    if (!representation || !tm) {
        return DT_INVALID_ARGUMENT;
    }

    tm->tm_year = representation->year - 1900;
    tm->tm_mon = representation->month - 1;
    tm->tm_mday = representation->day;
    tm->tm_hour = representation->hour;
    tm->tm_min = representation->minute;
    tm->tm_sec = representation->second;
    tm->tm_isdst = -1;
    if (dt_validate_representation(representation) == DT_TRUE) {
        // Setting day of week/year if valid representation has been provided
        status = dt_representation_day_of_week(representation, &dow);
        if (status != DT_OK) {
            return status;
        }
        tm->tm_wday = dow - 1;
        status = dt_representation_day_of_year(representation, &doy);
        if (status != DT_OK) {
            return status;
        }
        tm->tm_yday = doy - 1;
    }
    return DT_OK;
}