~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

  • Committer: Brian Aker
  • Date: 2010-03-31 22:22:16 UTC
  • mfrom: (1377.6.3 bug549858-fix)
  • Revision ID: brian@gaz-20100331222216-sl7qi1f5z6v83127
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
  DAYS_PER_NYEAR, DAYS_PER_LYEAR
117
117
};
118
118
 
119
 
#define LEAPS_THRU_END_OF(y)  ((y) / 4 - (y) / 100 + (y) / 400)
 
119
static inline int leaps_thru_end_of(int year)
 
120
{
 
121
  return ((year) / 4 - (year) / 100 + (year) / 400);
 
122
}
120
123
 
 
124
static inline bool isleap(int year)
 
125
{
 
126
  return (((year) % 4) == 0 && (((year) % 100) != 0 || ((year) % 400) == 0));
 
127
}
121
128
 
122
129
/*
123
130
  Converts time from time_t representation (seconds in UTC since Epoch)
181
188
    if (days < 0)
182
189
      newy--;
183
190
    days-= (newy - y) * DAYS_PER_NYEAR +
184
 
           LEAPS_THRU_END_OF(newy - 1) -
185
 
           LEAPS_THRU_END_OF(y - 1);
 
191
           leaps_thru_end_of(newy - 1) -
 
192
           leaps_thru_end_of(y - 1);
186
193
    y= newy;
187
194
  }
188
195
  tmp->year= y;
388
395
  */
389
396
  assert(mon > 0 && mon < 13);
390
397
  long days= year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR +
391
 
             LEAPS_THRU_END_OF(year - 1) -
392
 
             LEAPS_THRU_END_OF(EPOCH_YEAR - 1);
 
398
             leaps_thru_end_of(year - 1) -
 
399
             leaps_thru_end_of(EPOCH_YEAR - 1);
393
400
  days+= mon_starts[isleap(year)][mon - 1];
394
401
#else
395
402
  long norm_month= (mon - 1) % MONS_PER_YEAR;
396
403
  long a_year= year + (mon - 1)/MONS_PER_YEAR - (int)(norm_month < 0);
397
404
  long days= a_year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR +
398
 
             LEAPS_THRU_END_OF(a_year - 1) -
399
 
             LEAPS_THRU_END_OF(EPOCH_YEAR - 1);
 
405
             leaps_thru_end_of(a_year - 1) -
 
406
             leaps_thru_end_of(EPOCH_YEAR - 1);
400
407
  days+= mon_starts[isleap(a_year)]
401
408
                    [norm_month + (norm_month < 0 ? MONS_PER_YEAR : 0)];
402
409
#endif