/* return kStatus_Success: success in setting the time and starting the IRTC kStatus_InvalidArgument: failure. An error occurs because the datetime format is incorrect.  */
status_t IRTC_SetDatetime(RTC_Type *base, const irtc_datetime_t *datetime)
/* return kStatus_Success: success in setting the time and starting the IRTC kStatus_InvalidArgument: failure. An error occurs because the datetime format is incorrect.  */
status_t IRTC_SetDatetime(RTC_Type *base, const irtc_datetime_t *datetime)
{
    assert(NULL != datetime);
    status_t status = kStatus_Success;
    if (IRTC_CheckDatetimeFormat(datetime))
    {
        if (datetime->year < IRTC_BASE_YEAR)
        {
            base->YEARMON =
                RTC_YEARMON_YROFST(0x100U + datetime->year - IRTC_BASE_YEAR) | RTC_YEARMON_MON_CNT(datetime->month);
        }
        else
        {
            base->YEARMON = RTC_YEARMON_YROFST(datetime->year - IRTC_BASE_YEAR) | RTC_YEARMON_MON_CNT(datetime->month);
        }
        base->DAYS = RTC_DAYS_DOW(datetime->weekDay) | RTC_DAYS_DAY_CNT(datetime->day);
        base->HOURMIN = RTC_HOURMIN_HOUR_CNT(datetime->hour) | RTC_HOURMIN_MIN_CNT(datetime->minute);
        base->SECONDS = RTC_SECONDS_SEC_CNT(datetime->second);
    }
    else
    {
        status = kStatus_InvalidArgument;
    }
    return status;
}