~ubuntu-branches/ubuntu/saucy/nspr/saucy-updates

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/misc/prtime.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-08-10 11:34:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810113426-3uv4diflrkcbdimm
Tags: 4.8-0ubuntu1
* New upstream release: 4.8 (LP: #387812)
* adjust patches to changed upstreanm codebase
  - update debian/patches/99_configure.patch
* update shlibs symbols to include new API elements
  - update debian/libnspr4-0d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
#define COUNT_DAYS(Y)  ( ((Y)-1)*365 + COUNT_LEAPS(Y) )
73
73
#define DAYS_BETWEEN_YEARS(A, B)  (COUNT_DAYS(B) - COUNT_DAYS(A))
74
74
 
75
 
 
76
 
 
77
 
 
78
75
/*
79
76
 * Static variables used by functions in this file
80
77
 */
103
100
 */
104
101
 
105
102
static void        ComputeGMT(PRTime time, PRExplodedTime *gmt);
106
 
static int        IsLeapYear(PRInt16 year);
 
103
static int         IsLeapYear(PRInt16 year);
107
104
static void        ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset);
108
105
 
109
106
/*
113
110
 *
114
111
 *     Caveats:
115
112
 *     - we ignore leap seconds
116
 
 *     - our leap-year calculation is only correct for years 1901-2099
117
113
 *
118
114
 *------------------------------------------------------------------------
119
115
 */
167
163
    }
168
164
 
169
165
    /* Compute the time of day. */
170
 
    
 
166
 
171
167
    gmt->tm_hour = rem / 3600;
172
168
    rem %= 3600;
173
169
    gmt->tm_min = rem / 60;
174
170
    gmt->tm_sec = rem % 60;
175
171
 
176
 
    /* Compute the four-year span containing the specified time */
177
 
 
178
 
    tmp = numDays / (4 * 365 + 1);
179
 
    rem = numDays % (4 * 365 + 1);
180
 
 
181
 
    if (rem < 0) {
182
 
        tmp--;
183
 
        rem += (4 * 365 + 1);
184
 
    }
185
 
 
186
 
    /*
187
 
     * Compute the year after 1900 by taking the four-year span and
188
 
     * adjusting for the remainder.  This works because 2000 is a 
189
 
     * leap year, and 1900 and 2100 are out of the range.
190
 
     */
191
 
    
192
 
    tmp = (tmp * 4) + 1970;
193
 
    isLeap = 0;
194
 
 
195
 
    /*
196
 
     * 1970 has 365 days
197
 
     * 1971 has 365 days
198
 
     * 1972 has 366 days (leap year)
199
 
     * 1973 has 365 days
200
 
     */
201
 
 
202
 
    if (rem >= 365) {                                /* 1971, etc. */
203
 
        tmp++;
204
 
        rem -= 365;
205
 
        if (rem >= 365) {                        /* 1972, etc. */
206
 
            tmp++;
207
 
            rem -= 365;
208
 
            if (rem >= 366) {                        /* 1973, etc. */
209
 
                tmp++;
210
 
                rem -= 366;
211
 
            } else {
212
 
                isLeap = 1;
213
 
            }
214
 
        }
215
 
    }
216
 
 
217
 
    gmt->tm_year = tmp;
 
172
    /*
 
173
     * Compute the year by finding the 400 year period, then working
 
174
     * down from there.
 
175
     *
 
176
     * Since numDays is originally the number of days since January 1, 1970,
 
177
     * we must change it to be the number of days from January 1, 0001.
 
178
     */
 
179
 
 
180
    numDays += 719162;       /* 719162 = days from year 1 up to 1970 */
 
181
    tmp = numDays / 146097;  /* 146097 = days in 400 years */
 
182
    rem = numDays % 146097;
 
183
    gmt->tm_year = tmp * 400 + 1;
 
184
 
 
185
    /* Compute the 100 year period. */
 
186
 
 
187
    tmp = rem / 36524;    /* 36524 = days in 100 years */
 
188
    rem %= 36524;
 
189
    if (tmp == 4) {       /* the 400th year is a leap year */
 
190
        tmp = 3;
 
191
        rem = 36524;
 
192
    }
 
193
    gmt->tm_year += tmp * 100;
 
194
 
 
195
    /* Compute the 4 year period. */
 
196
 
 
197
    tmp = rem / 1461;     /* 1461 = days in 4 years */
 
198
    rem %= 1461;
 
199
    gmt->tm_year += tmp * 4;
 
200
 
 
201
    /* Compute which year in the 4. */
 
202
 
 
203
    tmp = rem / 365;
 
204
    rem %= 365;
 
205
    if (tmp == 4) {       /* the 4th year is a leap year */
 
206
        tmp = 3;
 
207
        rem = 365;
 
208
    }
 
209
 
 
210
    gmt->tm_year += tmp;
218
211
    gmt->tm_yday = rem;
 
212
    isLeap = IsLeapYear(gmt->tm_year);
219
213
 
220
214
    /* Compute the month and day of month. */
221
215
 
263
257
 *
264
258
 *------------------------------------------------------------------------
265
259
 */
266
 
#if defined(HAVE_WATCOM_BUG_2)
267
 
PRTime __pascal __export __loadds
268
 
#else
269
260
PR_IMPLEMENT(PRTime)
270
 
#endif
271
261
PR_ImplodeTime(const PRExplodedTime *exploded)
272
262
{
273
263
    PRExplodedTime copy;
510
500
 *     returns the time parameters for the local time zone
511
501
 *
512
502
 *     The following uses localtime() from the standard C library.
513
 
 *     (time.h)  This is our fallback implementation.  Unix and PC
514
 
 *     use this version.  Mac has its own machine-dependent
 
503
 *     (time.h)  This is our fallback implementation.  Unix, PC, and BeOS
 
504
 *     use this version.  A platform may have its own machine-dependent
515
505
 *     implementation of this function.
516
506
 *
517
507
 *-------------------------------------------------------------------------
539
529
 
540
530
#else
541
531
 
542
 
#if defined(XP_MAC)
543
 
extern struct tm *Maclocaltime(const time_t * t);
544
 
#endif
545
 
 
546
532
#define HAVE_LOCALTIME_MONITOR 1  /* We use 'monitor' to serialize our calls
547
533
                                   * to localtime(). */
548
534
static PRLock *monitor = NULL;
572
558
     * structs returned for timezones west of Greenwich when clock == 0.
573
559
     */
574
560
    
575
 
#if defined(XP_MAC)
576
 
    tmPtr = Maclocaltime(clock);
577
 
#else
578
561
    tmPtr = localtime(clock);
579
 
#endif
580
562
 
581
563
#if defined(WIN16) || defined(XP_OS2)
582
564
    if ( (PRInt32) *clock < 0 ||
614
596
        monitor = NULL;
615
597
    }
616
598
#endif
 
599
#ifdef WINCE
 
600
    _MD_CleanupTime();
 
601
#endif
617
602
}
618
603
 
619
604
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
761
746
    return retVal;
762
747
}
763
748
 
764
 
#endif    /* defined(XP_UNIX) !! defined(XP_PC) */
 
749
#endif    /* defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS) */
765
750
 
766
751
/*
767
752
 *------------------------------------------------------------------------
915
900
PR_IMPLEMENT(PRTimeParameters)
916
901
PR_GMTParameters(const PRExplodedTime *gmt)
917
902
{
918
 
#if defined(XP_MAC)
919
 
#pragma unused (gmt)
920
 
#endif
921
 
 
922
903
    PRTimeParameters retVal = { 0, 0 };
923
904
    return retVal;
924
905
}