Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
prtime.h File Reference
#include "prlong.h"

Go to the source code of this file.

Classes

struct  PRTimeParameters
struct  PRExplodedTime

Defines

#define PR_MSEC_PER_SEC   1000UL
#define PR_USEC_PER_SEC   1000000UL
#define PR_NSEC_PER_SEC   1000000000UL
#define PR_USEC_PER_MSEC   1000UL
#define PR_NSEC_PER_MSEC   1000000UL

Typedefs

typedef PRInt64 PRTime
typedef struct PRTimeParameters PRTimeParameters
typedef struct PRExplodedTime PRExplodedTime
typedef PRTimeParameters(PR_CALLBACKPRTimeParamFn )(const PRExplodedTime *gmt)

Functions

 PR_Now (void)
 NSPR_API (void) PR_ExplodeTime(PRTime usecs
 Prototypes for machine dependent function implementations.
 PR_ImplodeTime (const PRExplodedTime *exploded)
 NSPR_API (PRTimeParameters) PR_LocalTimeParameters(const PRExplodedTime *gmt)
 NSPR_API (PRStatus) PR_ParseTimeString(const char *string
 NSPR_API (PRUint32) PR_FormatTime(char *buf
 PR_FormatTimeUSEnglish (char *buf, PRUint32 bufSize, const char *format, const PRExplodedTime *tm)

Variables

PRTimeParamFn params
PRTimeParamFn PRExplodedTimeexploded
PRBool default_to_gmt
PRBool PRTimeresult
int buflen
int const char * fmt
int const char const
PRExplodedTime
tm

Class Documentation

struct PRTimeParameters

Definition at line 87 of file prtime.h.

Class Members
PRInt32 tp_dst_offset
PRInt32 tp_gmt_offset
struct PRExplodedTime

Definition at line 115 of file prtime.h.

Collaboration diagram for PRExplodedTime:
Class Members
PRInt32 tm_hour
PRInt32 tm_mday
PRInt32 tm_min
PRInt32 tm_month
PRTimeParameters tm_params
PRInt32 tm_sec
PRInt32 tm_usec
PRInt8 tm_wday
PRInt16 tm_yday
PRInt16 tm_year

Define Documentation

#define PR_MSEC_PER_SEC   1000UL

Definition at line 59 of file prtime.h.

#define PR_NSEC_PER_MSEC   1000000UL

Definition at line 63 of file prtime.h.

#define PR_NSEC_PER_SEC   1000000000UL

Definition at line 61 of file prtime.h.

#define PR_USEC_PER_MSEC   1000UL

Definition at line 62 of file prtime.h.

#define PR_USEC_PER_SEC   1000000UL

Definition at line 60 of file prtime.h.


Typedef Documentation

typedef PRInt64 PRTime

Definition at line 80 of file prtime.h.

Definition at line 158 of file prtime.h.


Function Documentation

NSPR_API ( void  )

Prototypes for machine dependent function implementations.

(Too bad NSPR's MD system blows so much that we have to reiterate every stinking thing we implement here in our MD header file.)

NSPR_API ( PRStatus  ) const
PR_FormatTimeUSEnglish ( char *  buf,
PRUint32  bufSize,
const char *  format,
const PRExplodedTime tm 
)

Definition at line 1809 of file prtime.c.

{
   char*         bufPtr = buf;
   const char*   fmtPtr;
   char          tmpBuf[ 40 ];        
   const int     tmpBufSize = sizeof( tmpBuf );

   
   for( fmtPtr=format; *fmtPtr != '\0'; fmtPtr++ )
   {
      if( *fmtPtr != '%' )
      {
         ADDCHAR( bufPtr, bufSize, *fmtPtr );
      }
      else
      {
         switch( *(++fmtPtr) )
         {
         case '%':
            /* escaped '%' character */
            ADDCHAR( bufPtr, bufSize, '%' );
            break;
            
         case 'a':
            /* abbreviated weekday name */
            ADDSTR( bufPtr, bufSize, abbrevDays[ time->tm_wday ] );
            break;
               
         case 'A':
            /* full weekday name */
            ADDSTR( bufPtr, bufSize, days[ time->tm_wday ] );
            break;
        
         case 'b':
            /* abbreviated month name */
            ADDSTR( bufPtr, bufSize, abbrevMonths[ time->tm_month ] );
            break;
        
         case 'B':
            /* full month name */
            ADDSTR(bufPtr, bufSize,  months[ time->tm_month ] );
            break;
        
         case 'c':
            /* Date and time. */
            PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%a %b %d %H:%M:%S %Y", time );
            ADDSTR( bufPtr, bufSize, tmpBuf );
            break;
        
         case 'd':
            /* day of month ( 01 - 31 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_mday );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;

         case 'H':
            /* hour ( 00 - 23 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_hour );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'I':
            /* hour ( 01 - 12 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",
                        (time->tm_hour%12) ? time->tm_hour%12 : (PRInt32) 12 );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'j':
            /* day number of year ( 001 - 366 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.3d",time->tm_yday + 1);
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'm':
            /* month number ( 01 - 12 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_month+1);
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'M':
            /* minute ( 00 - 59 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_min );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
       
         case 'p':
            /* locale's equivalent of either AM or PM */
            ADDSTR( bufPtr, bufSize, (time->tm_hour<12)?"AM":"PM" ); 
            break;
        
         case 'S':
            /* seconds ( 00 - 61 ), allows for leap seconds */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_sec );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
     
         case 'U':
            /* week number of year ( 00 - 53  ),  Sunday  is  the first day of week 1 */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 0 ) );
            ADDSTR( bufPtr, bufSize, tmpBuf );
            break;
        
         case 'w':
            /* weekday number ( 0 - 6 ), Sunday = 0 */
            PR_snprintf(tmpBuf,tmpBufSize,"%d",time->tm_wday );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'W':
            /* Week number of year ( 00 - 53  ),  Monday  is  the first day of week 1 */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 1 ) );
            ADDSTR( bufPtr, bufSize, tmpBuf );
            break;
        
         case 'x':
            /* Date representation */
            PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%m/%d/%y", time );
            ADDSTR( bufPtr, bufSize, tmpBuf );
            break;
        
         case 'X':
            /* Time representation. */
            PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%H:%M:%S", time );
            ADDSTR( bufPtr, bufSize, tmpBuf );
            break;
        
         case 'y':
            /* year within century ( 00 - 99 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.2d",time->tm_year % 100 );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'Y':
            /* year as ccyy ( for example 1986 ) */
            PR_snprintf(tmpBuf,tmpBufSize,"%.4d",time->tm_year );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;
        
         case 'Z':
            /* Time zone name or no characters if  no  time  zone exists.
             * Since time zone name is supposed to be independant of locale, we
             * defer to PR_FormatTime() for this option.
             */
            PR_FormatTime( tmpBuf, tmpBufSize, "%Z", time );
            ADDSTR( bufPtr, bufSize, tmpBuf ); 
            break;

         default:
            /* Unknown format.  Simply copy format into output buffer. */
            ADDCHAR( bufPtr, bufSize, '%' );
            ADDCHAR( bufPtr, bufSize, *fmtPtr );
            break;
            
         }
      }
   }

   ADDCHAR( bufPtr, bufSize, '\0' );
   return (PRUint32)(bufPtr - buf - 1);

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 254 of file prtime.c.

{
    PRExplodedTime copy;
    PRTime retVal;
    PRInt64 secPerDay, usecPerSec;
    PRInt64 temp;
    PRInt64 numSecs64;
    PRInt32 fourYears;
    PRInt32 remainder;
    PRInt32 numDays;
    PRInt32 numSecs;

    /* Normalize first.  Do this on our copy */
    copy = *exploded;
    PR_NormalizeTime(&copy, PR_GMTParameters);

    fourYears = (copy.tm_year - 1970) / 4;
    remainder = (copy.tm_year - 1970) % 4;
    if (remainder < 0) {
        remainder += 4;
        fourYears--;
    }
    numDays = fourYears * (4 * 365 + 1);
    switch (remainder) {
        case 0:
            break;
        case 1:  /* 1970 */
            numDays += 365;
            break;
        case 2:  /* 1970-1 */
            numDays += 365 * 2;
            break;
        case 3:  /* 1970-2 */
            numDays += 365 * 3 + 1;
            break;
    }

    numSecs = copy.tm_yday * 86400 + copy.tm_hour * 3600
            + copy.tm_min * 60 + copy.tm_sec;

    LL_I2L(temp, numDays);
    LL_I2L(secPerDay, 86400);
    LL_MUL(temp, temp, secPerDay);
    LL_I2L(numSecs64, numSecs);
    LL_ADD(numSecs64, numSecs64, temp);

    /* apply the GMT and DST offsets */
    LL_I2L(temp,  copy.tm_params.tp_gmt_offset);
    LL_SUB(numSecs64, numSecs64, temp);
    LL_I2L(temp,  copy.tm_params.tp_dst_offset);
    LL_SUB(numSecs64, numSecs64, temp);

    LL_I2L(usecPerSec, 1000000L);
    LL_MUL(temp, numSecs64, usecPerSec);
    LL_I2L(retVal, copy.tm_usec);
    LL_ADD(retVal, retVal, temp);

    return retVal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PR_Now ( void  )

Definition at line 109 of file beos.c.

{
       struct timeval tv;
       PRInt64 s, us, s2us;

       GETTIMEOFDAY(&tv);
       LL_I2L(s2us, PR_USEC_PER_SEC);
       LL_I2L(s, tv.tv_sec);
       LL_I2L(us, tv.tv_usec);
       LL_MUL(s, s, s2us);
       LL_ADD(s, s, us);
       return s;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 284 of file prtime.h.

Definition at line 269 of file prtime.h.

Definition at line 195 of file prtime.h.

int const char* fmt

Definition at line 284 of file prtime.h.

Definition at line 195 of file prtime.h.

Definition at line 269 of file prtime.h.

Definition at line 284 of file prtime.h.