Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
mactime.c File Reference
#include <OSUtils.h>
#include <Timer.h>
#include "primpl.h"
#include "mactime.h"

Go to the source code of this file.

Functions

static void MyReadLocation (MachineLocation *loc)
static long GMTDelta (void)
void MacintoshInitializeTime (void)
PRTime PR_Now (void)
PRTimeParameters PR_LocalTimeParameters (const PRExplodedTime *gmt)
PRIntervalTime _MD_GetInterval (void)
struct tmMaclocaltime (const time_t *t)

Variables

unsigned long gJanuaryFirst1970Seconds

Function Documentation

Definition at line 210 of file mactime.c.

{
    PRIntervalTime retVal;
    PRUint64 upTime, microtomilli; 

    /*
     * Use the Microseconds procedure to obtain the number of
     * microseconds elapsed since system startup time.
     */
    Microseconds((UnsignedWide *)&upTime);
    LL_I2L(microtomilli, PR_USEC_PER_MSEC);
    LL_DIV(upTime, upTime, microtomilli);
    LL_L2I(retVal, upTime);
       
    return retVal;
}
static long GMTDelta ( void  ) [static]

Definition at line 73 of file mactime.c.

{
    MachineLocation loc;
    long gmtDelta;

    MyReadLocation(&loc);
    gmtDelta = loc.u.gmtDelta & 0x00ffffff;
    if (gmtDelta & 0x00800000) {    /* test sign extend bit */
        gmtDelta |= 0xff000000;
    }
    return gmtDelta;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 86 of file mactime.c.

{
    /*
     * The NSPR epoch is midnight, Jan. 1, 1970 GMT.
     *
     * At midnight Jan. 1, 1970 GMT, the local time was
     *     midnight Jan. 1, 1970 + GMTDelta().
     *
     * Midnight Jan. 1, 1970 is 86400 * (365 * (1970 - 1904) + 17)
     *     = 2082844800 seconds since the Mac epoch.
     * (There were 17 leap years from 1904 to 1970.)
     *
     * So the NSPR epoch is 2082844800 + GMTDelta() seconds since
     * the Mac epoch.  Whew! :-)
     */
    gJanuaryFirst1970Seconds = 2082844800 + GMTDelta();
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct tm* Maclocaltime ( const time_t *  t) [read]

Definition at line 227 of file mactime.c.

{
       DateTimeRec dtr;
       MachineLocation loc;
       time_t macLocal = *t + gJanuaryFirst1970Seconds; /* GMT Mac */
       static struct tm statictime;
       static const short monthday[12] =
              {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};

       SecondsToDate(macLocal, &dtr);
       statictime.tm_sec = dtr.second;
       statictime.tm_min = dtr.minute;
       statictime.tm_hour = dtr.hour;
       statictime.tm_mday = dtr.day;
       statictime.tm_mon = dtr.month - 1;
       statictime.tm_year = dtr.year - 1900;
       statictime.tm_wday = dtr.dayOfWeek - 1;
       statictime.tm_yday = monthday[statictime.tm_mon]
              + statictime.tm_mday - 1;
       if (2 < statictime.tm_mon && !(statictime.tm_year & 3))
              ++statictime.tm_yday;
       MyReadLocation(&loc);
       statictime.tm_isdst = loc.u.dlsDelta;
       return(&statictime);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void MyReadLocation ( MachineLocation *  loc) [static]

Definition at line 61 of file mactime.c.

{
    static MachineLocation storedLoc;
    static Boolean didReadLocation = false;
    
    if (!didReadLocation) {
        ReadLocation(&storedLoc);
        didReadLocation = true;
    }
    *loc = storedLoc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 174 of file mactime.c.

{
#pragma unused (gmt)

    PRTimeParameters retVal;
    MachineLocation loc;

    MyReadLocation(&loc);

    /* 
     * On a Mac, the GMT value is in seconds east of GMT.  For example,
     * San Francisco is at -28,800 seconds (8 hours * 3600 seconds per hour)
     * east of GMT.  The gmtDelta field is a 3-byte value contained in a
     * long word, so you must take care to get it properly.
     */

    retVal.tp_gmt_offset = loc.u.gmtDelta & 0x00ffffff;
    if (retVal.tp_gmt_offset & 0x00800000) {    /* test sign extend bit */
       retVal.tp_gmt_offset |= 0xff000000;
    }

    /*
     * The daylight saving time value, dlsDelta, is a signed byte
     * value representing the offset for the hour field -- whether
     * to add 1 hour, subtract 1 hour, or make no change at all.
     */

    if (loc.u.dlsDelta) {
       retVal.tp_gmt_offset -= 3600;
       retVal.tp_dst_offset = 3600;
    } else {
       retVal.tp_dst_offset = 0;
    }
    return retVal;
}

Here is the call graph for this function:

Definition at line 118 of file mactime.c.

{
    unsigned long currentTime;    /* unsigned 32-bit integer, ranging
                                     from midnight Jan. 1, 1904 to 
                                     6:28:15 AM Feb. 6, 2040 */
    PRTime retVal;
    int64  usecPerSec;

    /*
     * Get the current time expressed as the number of seconds
     * elapsed since the Mac epoch, midnight, Jan. 1, 1904 (local time).
     * On a Mac, current time accuracy is up to a second.
     */
    GetDateTime(&currentTime);

    /*
     * Express the current time relative to the NSPR epoch,
     * midnight, Jan. 1, 1970 GMT.
     *
     * At midnight Jan. 1, 1970 GMT, the local time was
     *     midnight Jan. 1, 1970 + GMTDelta().
     *
     * Midnight Jan. 1, 1970 is 86400 * (365 * (1970 - 1904) + 17)
     *     = 2082844800 seconds since the Mac epoch.
     * (There were 17 leap years from 1904 to 1970.)
     *
     * So the NSPR epoch is 2082844800 + GMTDelta() seconds since
     * the Mac epoch.  Whew! :-)
     */
    currentTime = currentTime - 2082844800 - GMTDelta();

    /* Convert seconds to microseconds */
    LL_I2L(usecPerSec, PR_USEC_PER_SEC);
    LL_I2L(retVal, currentTime);
    LL_MUL(retVal, retVal, usecPerSec);

    return retVal;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 45 of file mactime.c.