~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.h

  • Committer: Jay Pipes
  • Date: 2009-02-04 15:25:30 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090204152530-27x7k0vjx1pd3g3o
default_week_format variable has gone the way of the Dodo, as have the
WEEK() and YEARWEEK() functions.  These two functions, along with week_mode
(default_week_format) were inconsistent with standards and made redundant
by the DATE_FORMAT() function.

Cleaned up the former week_number_from_gregorian_date() function into
a simpler, strftime()-based solution in sync with PosgreSQL and SQL/ISO standards.

Clean up of the EXTRACT() function to use new temporal system and produce
proper errors on bad temporal values.

NOTE: Test cases for EXTRACT and cleanup of the func_time.test case have not
yet been committed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
274
274
                       , uint32_t minute
275
275
                       , uint32_t second);
276
276
 
277
 
/* 
278
 
 * I don't like using these defines, but probably good to keep in sync
279
 
 * with MySQL's week mode stuff.. 
280
 
 */
281
 
#define DRIZZLE_WEEK_MODE_MONDAY_FIRST_DAY   1
282
 
#define DRIZZLE_WEEK_MODE_USE_ISO_8601_1988  2
283
 
#define DRIZZLE_WEEK_MODE_WEEK_RANGE_IS_ORDINAL 4
284
 
 
285
277
/**
286
278
 * Returns the number of the week from a supplied year, month, and
287
 
 * date in the Gregorian proleptic calendar.
288
 
 *
289
 
 * The week number returned will depend on the values of the
290
 
 * various boolean flags passed to the function.
291
 
 *
292
 
 * The flags influence returned values in the following ways:
293
 
 *
294
 
 * sunday_is_first_day_of_week
295
 
 *
296
 
 * If TRUE, Sunday is first day of week
297
 
 * If FALSE,    Monday is first day of week
298
 
 *
299
 
 * week_range_is_ordinal
300
 
 *
301
 
 * If FALSE, the week is in range 0-53
302
 
 *
303
 
 * Week 0 is returned for the the last week of the previous year (for
304
 
 * a date at start of january) In this case one can get 53 for the
305
 
 * first week of next year.  This flag ensures that the week is
306
 
 * relevant for the given year. 
307
 
 *
308
 
 * If TRUE, the week is in range 1-53.
309
 
 *
310
 
 * In this case one may get week 53 for a date in January (when
311
 
 * the week is that last week of previous year) and week 1 for a
312
 
 * date in December.
313
 
 *
314
 
 * use_iso_8601_1988
315
 
 *
316
 
 * If TRUE, the weeks are numbered according to ISO 8601:1988
317
 
 *
318
 
 * ISO 8601:1988 means that if the week containing January 1 has
319
 
 * four or more days in the new year, then it is week 1;
320
 
 * Otherwise it is the last week of the previous year, and the
321
 
 * next week is week 1.
322
 
 *
323
 
 * If FALSE, the week that contains the first 'first-day-of-week' is week 1.
 
279
 * date in the Gregorian proleptic calendar.  We use strftime() and
 
280
 * the %U, %W, and %V format specifiers depending on the value
 
281
 * of the sunday_is_first_day_of_week parameter.
324
282
 *
325
283
 * @param Subject year
326
284
 * @param Subject month
327
285
 * @param Subject day
328
286
 * @param Is sunday the first day of the week?
329
 
 * @param Is the week range ordinal?
330
 
 * @param Should we use ISO 8601:1988 rules?
331
287
 * @param Pointer to a uint32_t to hold the resulting year, which 
332
288
 *        may be incremented or decremented depending on flags
333
289
 */
334
290
uint32_t week_number_from_gregorian_date(uint32_t year
335
291
                                       , uint32_t month
336
292
                                       , uint32_t day
337
 
                                       , bool sunday_is_first_day_of_week
338
 
                                       , bool week_range_is_ordinal
339
 
                                       , bool use_iso_8601_1988
340
 
                                       , uint32_t *year_out);
 
293
                                       , bool sunday_is_first_day_of_week);
341
294
 
 
295
/**
 
296
 * Returns the ISO week number of a supplied year, month, and
 
297
 * date in the Gregorian proleptic calendar.  We use strftime() and
 
298
 * the %V format specifier to do the calculation, which yields a
 
299
 * correct ISO 8601:1988 week number.
 
300
 *
 
301
 * The final year_out parameter is a pointer to an integer which will
 
302
 * be set to the year in which the week belongs, according to ISO8601:1988, 
 
303
 * which may be different from the Gregorian calendar year.
 
304
 *
 
305
 * @see http://en.wikipedia.org/wiki/ISO_8601
 
306
 *
 
307
 * @param Subject year
 
308
 * @param Subject month
 
309
 * @param Subject day
 
310
 * @param Pointer to a uint32_t to hold the resulting year, which 
 
311
 *        may be incremented or decremented depending on flags
 
312
 */
 
313
uint32_t iso_week_number_from_gregorian_date(uint32_t year
 
314
                                           , uint32_t month
 
315
                                           , uint32_t day
 
316
                                           , uint32_t *year_out);
342
317
#ifdef __cplusplus
343
318
}
344
319
#endif