예제 #1
0
파일: empdis.c 프로젝트: fstltna/empserver
void
enforce_minimum_session_time(void)
{
    struct natstr *natp = getnatp(player->cnum);

    time_t dt = natp->nat_last_logout - natp->nat_last_login;
    if (dt > seconds_since_midnight(natp->nat_last_logout))
	dt = seconds_since_midnight(natp->nat_last_logout);
    if (dt < 15)
	natp->nat_timeused += 15 - dt;
    putnat(natp);
}
예제 #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
/** Calculates the number of seconds since midnight
 *
 * @param btime [in] BACNET_TIME containing the time to convert
 *
 * @return seconds since midnight
 */
uint32_t datetime_seconds_since_midnight(
    BACNET_TIME * btime)
{
    uint32_t seconds = 0;

    if (btime) {
        seconds = seconds_since_midnight(btime->hour, btime->min, btime->sec);
    }

    return seconds;
}
예제 #4
0
void testBACnetDateTimeSeconds(
    Test * pTest)
{
    uint8_t hour = 0, minute = 0, second = 0;
    uint8_t test_hour = 0, test_minute = 0, test_second = 0;
    uint32_t seconds = 0, test_seconds;

    for (hour = 0; hour < 24; hour++) {
        for (minute = 0; minute < 60; minute += 3) {
            for (second = 0; second < 60; second += 17) {
                seconds = seconds_since_midnight(hour, minute, second);
                seconds_since_midnight_into_hms(seconds, &test_hour,
                    &test_minute, &test_second);
                test_seconds =
                    seconds_since_midnight(test_hour, test_minute,
                    test_second);
                ct_test(pTest, seconds == test_seconds);
            }
        }
    }
}
예제 #5
0
파일: empdis.c 프로젝트: fstltna/empserver
void
update_timeused_login(time_t now)
{
    struct natstr *natp = getnatp(player->cnum);
    time_t midnight_secs = seconds_since_midnight(now);

    if (now - natp->nat_last_logout > midnight_secs) {
	natp->nat_timeused = 0;
	putnat(natp);
    }
    player->lasttime = now;
}
예제 #6
0
파일: empdis.c 프로젝트: fstltna/empserver
void
update_timeused(time_t now)
{
    struct natstr *natp = getnatp(player->cnum);
    time_t midnight_secs = seconds_since_midnight(now);
    time_t dt = now - player->lasttime;

    if (dt > midnight_secs)
	natp->nat_timeused = midnight_secs;
    else
	natp->nat_timeused += dt;
    player->lasttime = now;
    putnat(natp);
}
예제 #7
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 = datetime_days_since_epoch(&bdatetime->date);

    /* more minutes than in a day? */
    days = minutes / (24 * 60);
    bdatetime_days += days;
    minutes -= (days * 24 * 60);
    /* less minutes - previous day? */
    if (minutes < 0) {
        /* convert to positive for easier math */
        minutes *= -1;
        if ((uint32_t)minutes > bdatetime_minutes) {
            /* previous day */
            bdatetime_days -= 1;
            bdatetime_minutes += ((24 * 60) - minutes);
        } else {
            bdatetime_minutes -= minutes;
            days = bdatetime_minutes / (24 * 60);
            bdatetime_days += days;
            bdatetime_minutes -= (days * 24 * 60);
        }
    } else {
        /* more days than current datetime? */
        bdatetime_minutes += minutes;
        days = bdatetime_minutes / (24 * 60);
        bdatetime_days += days;
        bdatetime_minutes -= (days * 24 * 60);
    }

    /* convert bdatetime from seconds and days */
    seconds_since_midnight_into_hms(bdatetime_minutes * 60,
        &bdatetime->time.hour, &bdatetime->time.min, NULL);
    datetime_days_since_epoch_into_date(bdatetime_days, &bdatetime->date);
}