예제 #1
0
void testDateEpoch(
    Test * pTest)
{
    uint32_t days = 0;
    uint16_t year = 0, test_year = 0;
    uint8_t month = 0, test_month = 0;
    uint8_t day = 0, test_day = 0;

    days = days_since_epoch(1900, 1, 1);
    ct_test(pTest, days == 0);
    days_since_epoch_into_ymd(days, &year, &month, &day);
    ct_test(pTest, year == 1900);
    ct_test(pTest, month == 1);
    ct_test(pTest, day == 1);


    for (year = 1900; year <= 2154; year++) {
        for (month = 1; month <= 12; month++) {
            for (day = 1; day <= month_days(year, month); day++) {
                days = days_since_epoch(year, month, day);
                days_since_epoch_into_ymd(days, &test_year, &test_month,
                    &test_day);
                ct_test(pTest, year == test_year);
                ct_test(pTest, month == test_month);
                ct_test(pTest, day == test_day);
            }
        }
    }
}
예제 #2
0
/** Utility to add or subtract minutes to a BACnet DateTime structure
 *
 * @param bdatetime [in] the starting date and time
 * @param minutes [in] number of minutes to add or subtract from the time
 */
void datetime_add_minutes(
    BACNET_DATE_TIME * bdatetime,
    int32_t minutes)
{
    uint32_t bdatetime_minutes = 0;
    uint32_t bdatetime_days = 0;
    int32_t days = 0;

    /* convert bdatetime to seconds and days */
    bdatetime_minutes =
        seconds_since_midnight(bdatetime->time.hour, bdatetime->time.min,
        bdatetime->time.sec) / 60;
    bdatetime_days =
        days_since_epoch(bdatetime->date.year, bdatetime->date.month,
        bdatetime->date.day);

    /* add */
    days = minutes / (24 * 60);
    bdatetime_days += days;
    minutes -= (days * 24 * 60);
    bdatetime_minutes += minutes;
    days = bdatetime_minutes / (24 * 60);
    bdatetime_days += days;

    /* convert bdatetime from seconds and days */
    seconds_since_midnight_into_hms(bdatetime_minutes * 60,
        &bdatetime->time.hour, &bdatetime->time.min, NULL);
    days_since_epoch_into_ymd(bdatetime_days, &bdatetime->date.year,
        &bdatetime->date.month, &bdatetime->date.day);
    bdatetime->date.wday =
        day_of_week(bdatetime->date.year, bdatetime->date.month,
        bdatetime->date.day);
}
예제 #3
0
void datetime_days_since_epoch_into_date(
    uint32_t days,
    BACNET_DATE * bdate)
{
    uint16_t year = 0;
    uint8_t month = 0;
    uint8_t day = 0;

    days_since_epoch_into_ymd(days, &year, &month, &day);
    datetime_set_date(bdate, year, month, day);
}