Example #1
0
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);
    }
Example #2
0
File: timeLib.c Project: phoboz/vmx
void __getLocale(
    char            *buffer,
    int              desc,
    const struct tm *tmp,
    TIMELOCALE      *timeInfo,
    int *size
    )
{
    char  zoneBuffer[sizeof(ZONEBUFFER)];
    char *ptr = NULL;

    /* Select item */
    switch (desc)
    {
        case DATETIME:
            ptr = timeInfo->_Format[DATETIME];
            break;

        case DATE:
            ptr = timeInfo->_Format[DATE];
            break;

        case TIMEO:
            ptr = timeInfo->_Format[TIMEO];
            break;

        case AMPM:
            ptr = timeInfo->_Ampm[(tmp->tm_hour < 12) ? 0 : 1];
            break;

        case ZONE:
            __getZoneInfo(zoneBuffer, NAME, timeInfo);
            ptr = zoneBuffer;
            break;
    }

    /* Set size */
    *size = strlen(ptr);

    /* Get string */
    strcpy(buffer, ptr);
}