Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
prmjtime.h File Reference
#include <time.h>
#include "jslong.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  PRMJTime


#define PRMJ_USEC_PER_SEC   1000000L
#define PRMJ_USEC_PER_MSEC   1000L




JSInt64 PRMJ_Now (void)
JSInt32 PRMJ_LocalGMTDifference (void)
size_t PRMJ_FormatTime (char *buf, int buflen, char *fmt, PRMJTime *tm)
JSInt64 PRMJ_DSTOffset (JSInt64 local_time)

Class Documentation

struct PRMJTime

Definition at line 59 of file prmjtime.h.

Class Members
JSInt8 tm_hour
JSInt8 tm_isdst
JSInt8 tm_mday
JSInt8 tm_min
JSInt8 tm_mon
JSInt8 tm_sec
JSInt32 tm_usec
JSInt8 tm_wday
JSInt16 tm_yday
JSInt16 tm_year

Define Documentation

Definition at line 74 of file prmjtime.h.

#define PRMJ_USEC_PER_SEC   1000000L

Definition at line 73 of file prmjtime.h.

Typedef Documentation

typedef typedefJS_BEGIN_EXTERN_C struct PRMJTime

Definition at line 54 of file prmjtime.h.

Function Documentation

JSInt64 PRMJ_DSTOffset ( JSInt64  local_time)

Definition at line 216 of file prmjtime.c.

    JSInt64 us2s;
    time_t local;
    JSInt32 diff;
    JSInt64  maxtimet;
    struct tm tm;
    PRMJTime prtm;
    struct tm *ptm;

    JSLL_DIV(local_time, local_time, us2s);

    /* get the maximum of time_t value */

    } else if(!JSLL_GE_ZERO(local_time)){
        /*go ahead a day to make localtime work (does not work with 0) */
    ptm = localtime(&local);
        return JSLL_ZERO;
    tm = *ptm;
    localtime_r(&local,&tm); /* get dst information */

    diff = ((tm.tm_hour - prtm.tm_hour) * PRMJ_HOUR_SECONDS) +
       ((tm.tm_min - prtm.tm_min) * 60);

    if(diff < 0){
       diff += PRMJ_DAY_SECONDS;




Here is the call graph for this function:

Here is the caller graph for this function:

size_t PRMJ_FormatTime ( char *  buf,
int  buflen,
char *  fmt,
PRMJTime tm 

Definition at line 269 of file prmjtime.c.

#if defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS)
    struct tm a;

    /* Zero out the tm struct.  Linux, SunOS 4 struct tm has extra members int
     * tm_gmtoff, char *tm_zone; when tm_zone is garbage, strftime gets
     * confused and dumps core.  NSPR20 prtime.c attempts to fill these in by
     * calling mktime on the partially filled struct, but this doesn't seem to
     * work as well; the result string has "can't get timezone" for ECMA-valid
     * years.  Might still make sense to use this, but find the range of years
     * for which valid tz information exists, and map (per ECMA hint) from the
     * given year into that range.

     * N.B. This hasn't been tested with anything that actually _uses_
     * tm_gmtoff; zero might be the wrong thing to set it to if you really need
     * to format a time.  This fix is for jsdate.c, which only uses
     * JS_FormatTime to get a string representing the time zone.  */
    memset(&a, 0, sizeof(struct tm));

    a.tm_sec = prtm->tm_sec;
    a.tm_min = prtm->tm_min;
    a.tm_hour = prtm->tm_hour;
    a.tm_mday = prtm->tm_mday;
    a.tm_mon = prtm->tm_mon;
    a.tm_wday = prtm->tm_wday;
    a.tm_year = prtm->tm_year - 1900;
    a.tm_yday = prtm->tm_yday;
    a.tm_isdst = prtm->tm_isdst;

    /* Even with the above, SunOS 4 seems to detonate if tm_zone and tm_gmtoff
     * are null.  This doesn't quite work, though - the timezone is off by
     * tzoff + dst.  (And mktime seems to return -1 for the exact dst
     * changeover time.)


#if defined(SUNOS4)
    if (mktime(&a) == -1) {
        /* Seems to fail whenever the requested date is outside of the 32-bit
         * UNIX epoch.  We could proceed at this point (setting a.tm_zone to
         * "") but then strftime returns a string with a 2-digit field of
         * garbage for the year.  So we return 0 and hope jsdate.c
         * will fall back on toString.
        return 0;

    return strftime(buf, buflen, fmt, &a);

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 90 of file prmjtime.c.

#if defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS)
    struct tm ltime;

    /* get the difference between this time zone and GMT */
    memset((char *)&ltime,0,sizeof(ltime));
    ltime.tm_mday = 2;
    ltime.tm_year = 70;
#ifdef SUNOS4
    ltime.tm_zone = 0;
    ltime.tm_gmtoff = 0;
    return timelocal(&ltime) - (24 * 3600);
    return mktime(&ltime) - (24L * 3600L);

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 149 of file prmjtime.c.

#ifdef XP_OS2
    JSInt64 s, us, ms2us, s2us;
    struct timeb b;
#ifdef XP_WIN
    JSInt64 s, us,
    win2un = JSLL_INIT(0x19DB1DE, 0xD53E8000),
    ten = JSLL_INIT(0, 10);
    FILETIME time, midnight;
#if defined(XP_UNIX) || defined(XP_BEOS)
    struct timeval tv;
    JSInt64 s, us, s2us;
#endif /* XP_UNIX */

#ifdef XP_OS2
    JSLL_UI2L(s, b.time);
    JSLL_UI2L(us, b.millitm);
    JSLL_MUL(us, us, ms2us);
    JSLL_MUL(s, s, s2us);
    JSLL_ADD(s, s, us);
    return s;
#ifdef XP_WIN
    /* The windows epoch is around 1600. The unix epoch is around 1970.
       win2un is the difference (in windows time units which are 10 times
       more precise than the JS time unit) */
    /* Win9x gets confused at midnight;en-us;q224423
       So if the low part (precision <8mins) is 0 then we get the time
       again. */
    if (!time.dwLowDateTime) {
        time.dwHighDateTime = midnight.dwHighDateTime;
    JSLL_UI2L(s, time.dwHighDateTime);
    JSLL_UI2L(us, time.dwLowDateTime);
    JSLL_SHL(s, s, 32);
    JSLL_ADD(s, s, us);
    JSLL_SUB(s, s, win2un);
    JSLL_DIV(s, s, ten);
    return s;

#if defined(XP_UNIX) || defined(XP_BEOS)
#ifdef _SVID_GETTOD   /* Defined only on Solaris, see Solaris <sys/types.h> */
    gettimeofday(&tv, 0);
#endif /* _SVID_GETTOD */
    JSLL_UI2L(s, tv.tv_sec);
    JSLL_UI2L(us, tv.tv_usec);
    JSLL_MUL(s, s, s2us);
    JSLL_ADD(s, s, us);
    return s;
#endif /* XP_UNIX */

Here is the call graph for this function:

Here is the caller graph for this function: