コード例 #1
0
ファイル: timeLib.c プロジェクト: phoboz/vmx
int __getTime(
    const time_t timer,
    struct tm   *tmp
    )
{
    int    days;
    int    timeOfDay;
    int    year;
    int    mon;
    ldiv_t result;

    /* Calculate days since epoch */
    days = timer / SECSPERDAY;
    timeOfDay = timer % SECSPERDAY;
    if (timeOfDay < 0)
    {
        timeOfDay += SECSPERDAY;
        days      -= 1;
    }

    /* Calculate years since epoch */
    year = days / DAYSPERYEAR;
    while (__daysSinceEpoch(year, 0) > days)
    {
        year--;
    }

    /* Calculcate weekday */
    tmp->tm_wday = (days + EPOCH_WDAY) % DAYSPERWEEK;
    if (tmp->tm_wday < 0)
    {
        tmp->tm_wday += DAYSPERWEEK;
    }

    /* Find year and days left */
    days -= __daysSinceEpoch(year, 0);
    year += EPOCH_YEAR;

    /* Calculate month */
    for (mon = 0;
         (days >= __julday(year - TM_YEAR_BASE, mon + 1, 0)) && (mon < 11);
         mon++);

    /* Setup time structure */
    tmp->tm_year = year - TM_YEAR_BASE;
    tmp->tm_mon  = mon;
    tmp->tm_mday = (days - __julday(tmp->tm_year, mon, 0)) + 1;
    tmp->tm_yday = __julday(tmp->tm_year, mon, tmp->tm_mday) - 1;
    tmp->tm_hour = timeOfDay / SECSPERHOUR;

    timeOfDay %= SECSPERHOUR;
    ldiv_r((long) timeOfDay, (long) SECSPERMIN, &result);
    tmp->tm_min = result.quot;
    tmp->tm_sec = result.rem;

    return OK;
}
コード例 #2
0
ファイル: mktime.c プロジェクト: andy345/vxworks5
time_t mktime
    (
    struct tm * timeptr	/* pointer to broken-down structure */
    )
    {
    time_t timeIs = 0;
    int    days   = 0;
    char   zoneBuf [sizeof (ZONEBUFFER)];

    /* Validate tm structure */
    __tmValidate (timeptr);

    /* Calulate time_t value */
    /* time */
    timeIs += (timeptr->tm_sec +
    	      (timeptr->tm_min * SECSPERMIN) +
    	      (timeptr->tm_hour * SECSPERHOUR));

    /* date */
    days += __julday (timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday);

    timeptr->tm_yday = (days - 1);

    if ((timeptr->tm_year + TM_YEAR_BASE) < EPOCH_YEAR )
    	return ((time_t) ERROR);

    /* days in previous years */
    days = __daysSinceEpoch (timeptr->tm_year - (EPOCH_YEAR - TM_YEAR_BASE),
    		             timeptr->tm_yday );

    timeptr->tm_wday = (days + EPOCH_WDAY) % DAYSPERWEEK;

    timeIs += (days * SECSPERDAY);

    /* correct for day light saving */
    /* validate again for the extra DST hour */
    if ((timeptr->tm_isdst = __getDstInfo (timeptr, __loctime)))
    	{
    	timeIs -= SECSPERHOUR;
    	__tmValidate (timeptr);
    	}

    /* correct for zone offset from UTC */
    __getZoneInfo (zoneBuf, TIMEOFFSET, __loctime);
    timeIs += (atoi (zoneBuf) * SECSPERMIN);

    return(timeIs);
    }
コード例 #3
0
ファイル: gmtime.c プロジェクト: andy345/vxworks5
int __getTime
    (
    const time_t timer,		/* time represented as seconds from epoch */
    struct tm *  tmp		/* pointer to broken-down time structure */
    )
    {
    long	days;
    long	timeOfDay;
    long	year;
    long	mon;
    ldiv_t	result; 

    /* Calulate number of days since epoch */

    days = timer / SECSPERDAY;
    timeOfDay = timer % SECSPERDAY;

    /* If time of day is negative, subtract one day, and add SECSPERDAY
     * to make it positive.
     */

    if(timeOfDay<0)
    	{
	timeOfDay+=SECSPERDAY;
	days-=1;
    	}

    /* Calulate number of years since epoch */

    year = days / DAYSPERYEAR;
    while ( __daysSinceEpoch (year, 0) > days )
    	year--;

    /* Calulate the day of the week */

    tmp->tm_wday = (days + EPOCH_WDAY) % DAYSPERWEEK;

	/*
	 * If there is a negative weekday, add DAYSPERWEEK to make it positive
	 */
	if(tmp->tm_wday<0)
		tmp->tm_wday+=DAYSPERWEEK;

    /* Find year and remaining days */

    days -= __daysSinceEpoch (year, 0);
    year += EPOCH_YEAR;

    /* Find month */
    /* __jullday needs years since TM_YEAR_BASE (SPR 4251) */

    for  ( mon = 0; 
         (days >= __julday (year - TM_YEAR_BASE, mon + 1, 0)) && (mon < 11); 
         mon++ )
	;

    /* Initialise tm structure */

    tmp->tm_year = year - TM_YEAR_BASE; /* years since 1900 */
    tmp->tm_mon  = mon;
    tmp->tm_mday = (days - __julday (tmp->tm_year, mon, 0)) + 1;
    tmp->tm_yday = __julday (tmp->tm_year, mon, tmp->tm_mday) - 1;
    tmp->tm_hour = timeOfDay / SECSPERHOUR;

    timeOfDay  %= SECSPERHOUR;
    ldiv_r (timeOfDay, SECSPERMIN, &result);
    tmp->tm_min = result.quot;
    tmp->tm_sec = result.rem;

    return(OK);
    }