Exemplo n.º 1
0
nOS_TimeDate nOS_TimeConvert (nOS_Time time)
{
    nOS_TimeDate    timedate;
    uint16_t        days;

    /* First extract HH:MM:SS from _timeCounter */
    timedate.second = time % 60;
    time /= 60;
    timedate.minute = time % 60;
    time /= 60;
    timedate.hour = time % 24;
    time /= 24;
    /* At this point, time is now in number of days since 1st January 1970 */

    /* Second, get week day we are */
    /* 1st January 1970 was a Thursday (4th day or index 3) */
    /* weekday go from 1 (Monday) to 7 (Sunday) */
    timedate.weekday = ((time + 3) % 7) + 1;

    /* Third, find in which year we are */
    timedate.year = 1970;
    days = 365; /* 1970 is not a leap year */
    while (time >= days) {
        time -= days;
        timedate.year++;
        days = DAYS_PER_YEAR(timedate.year);
    }

    /* Fourth, find in which month of the present year we are */
    timedate.month = 1;
    days = 31;  /* January have 31 days */
    while (time >= days) {
        time -= days;
        timedate.month++;
        days = DAYS_PER_MONTH(timedate.month, timedate.year);
    }

    /* Last, we have in which day of month we are */
    timedate.day = (uint8_t)(time + 1);

    return timedate;
}
Exemplo n.º 2
0
nOS_Time nOS_TimeDateConvert (nOS_TimeDate *timedate)
{
    nOS_Time    time = 0;

#if (NOS_CONFIG_SAFE > 0)
    if (timedate != NULL)
#endif
    {
        uint16_t    year;
        uint8_t     month;

        /* Increment time variable until we reach timedate given by user */

        /* Do not count half day */
        time += ((timedate->day-1) * 86400UL); /* 86400 seconds per day */

        /* Do not count on-going month */
        month = 1;
        while (month < timedate->month) {
            time += (DAYS_PER_MONTH(month, timedate->year) * 86400UL);
            month++;
        }

        /* Do not count on-going year */
        year = 1970;
        while (year < timedate->year) {
            time += (DAYS_PER_YEAR(year) * 86400UL);
            year++;
        }

        time += (timedate->hour * 3600UL);
        time += (timedate->minute * 60UL);
        time += timedate->second;
    }

    return time;
}
Exemplo n.º 3
0
bool SchedulerTask::UpdateTime()
{
    if (!countDown)
        return true;
    switch (taskAttribs.bmPeriodType)
    {
    case enHourly:
        timeToFire += SECS_PER_HOUR;
        break;
    case enDaily:
        timeToFire += SECS_PER_DAY;
        break;
    case enWeekly:
        timeToFire += SECS_PER_WEEK;
        break;
    case enMonthly:
        timeToFire += DaysPerMonth(timeToFire) * SECS_PER_DAY;
        break;
    case enYearly:
        timeToFire += DAYS_PER_YEAR(year(timeToFire));
        break;
    }
    return true;
}