~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_time.c

Merged in changes from Andrey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
/* Position for YYYY-DD-MM HH-MM-DD.FFFFFF AM in default format */
32
32
 
33
 
static uchar internal_format_positions[]=
34
 
{0, 1, 2, 3, 4, 5, 6, (uchar) 255};
 
33
static unsigned char internal_format_positions[]=
 
34
{0, 1, 2, 3, 4, 5, 6, (unsigned char) 255};
35
35
 
36
36
static char time_separator=':';
37
37
 
38
38
static uint32_t const days_at_timestart=719528; /* daynr at 1970.01.01 */
39
 
uchar days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
 
39
unsigned char days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
40
40
 
41
41
/*
42
42
  Offset of system time zone from UTC in seconds used to speed up 
47
47
 
48
48
/* Calc days in one year. works with 0 <= year <= 99 */
49
49
 
50
 
uint calc_days_in_year(uint year)
 
50
uint32_t calc_days_in_year(uint32_t year)
51
51
{
52
52
  return ((year & 3) == 0 && (year%100 || (year%400 == 0 && year)) ?
53
53
          366 : 365);
156
156
#define MAX_DATE_PARTS 8
157
157
 
158
158
enum enum_drizzle_timestamp_type
159
 
str_to_datetime(const char *str, uint length, DRIZZLE_TIME *l_time,
160
 
                uint flags, int *was_cut)
 
159
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
 
160
                uint32_t flags, int *was_cut)
161
161
{
162
 
  uint field_length, year_length=4, digits, i, number_of_fields;
163
 
  uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
164
 
  uint add_hours= 0, start_loop;
 
162
  uint32_t field_length, year_length=4, digits, i, number_of_fields;
 
163
  uint32_t date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
 
164
  uint32_t add_hours= 0, start_loop;
165
165
  uint32_t not_zero_date, allow_space;
166
166
  bool is_internal_format;
167
167
  const char *pos, *last_field_pos=NULL;
168
168
  const char *end=str+length;
169
 
  const uchar *format_position;
 
169
  const unsigned char *format_position;
170
170
  bool found_delimitier= 0, found_space= 0;
171
 
  uint frac_pos, frac_len;
 
171
  uint32_t frac_pos, frac_len;
172
172
 
173
173
  *was_cut= 0;
174
174
 
244
244
    2003-03-03 20:00:20 AM
245
245
    20:00:20.000000 AM 03-03-2000
246
246
  */
247
 
  i= max((uint) format_position[0], (uint) format_position[1]);
 
247
  i= cmax((uint) format_position[0], (uint) format_position[1]);
248
248
  set_if_bigger(i, (uint) format_position[2]);
249
249
  allow_space= ((1 << i) | (1 << format_position[6]));
250
250
  allow_space&= (1 | 2 | 4 | 8);
256
256
       i++)
257
257
  {
258
258
    const char *start= str;
259
 
    uint32_t tmp_value= (uint) (uchar) (*str++ - '0');
 
259
    uint32_t tmp_value= (uint) (unsigned char) (*str++ - '0');
260
260
    while (str != end && my_isdigit(&my_charset_utf8_general_ci,str[0]) &&
261
261
           (!is_internal_format || --field_length))
262
262
    {
263
 
      tmp_value=tmp_value*10 + (uint32_t) (uchar) (*str - '0');
 
263
      tmp_value=tmp_value*10 + (uint32_t) (unsigned char) (*str - '0');
264
264
      str++;
265
265
    }
266
266
    date_len[i]= (uint) (str - start);
369
369
      date[frac_pos]*= (uint) log_10_int[6 - frac_len];
370
370
    l_time->second_part= date[frac_pos];
371
371
 
372
 
    if (format_position[7] != (uchar) 255)
 
372
    if (format_position[7] != (unsigned char) 255)
373
373
    {
374
374
      if (l_time->hour > 12)
375
375
      {
467
467
     1  error
468
468
*/
469
469
 
470
 
bool str_to_time(const char *str, uint length, DRIZZLE_TIME *l_time,
 
470
bool str_to_time(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
471
471
                    int *warning)
472
472
{
473
473
  uint32_t date[5];
474
474
  uint64_t value;
475
475
  const char *end=str+length, *end_of_days;
476
476
  bool found_days,found_hours;
477
 
  uint state;
 
477
  uint32_t state;
478
478
 
479
479
  l_time->neg=0;
480
480
  *warning= 0;
558
558
    /* Fix the date to assume that seconds was given */
559
559
    if (!found_hours && !found_days)
560
560
    {
561
 
      bmove_upp((uchar*) (date+4), (uchar*) (date+state),
 
561
      bmove_upp((unsigned char*) (date+4), (unsigned char*) (date+state),
562
562
                sizeof(long)*(state-1));
563
563
      memset(date, 0, sizeof(long)*(4-state));
564
564
    }
571
571
  if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_utf8_general_ci,str[1]))
572
572
  {
573
573
    int field_length= 5;
574
 
    str++; value=(uint) (uchar) (*str - '0');
 
574
    str++; value=(uint) (unsigned char) (*str - '0');
575
575
    while (++str != end && my_isdigit(&my_charset_utf8_general_ci, *str))
576
576
    {
577
577
      if (field_length-- > 0)
578
 
        value= value*10 + (uint) (uchar) (*str - '0');
 
578
        value= value*10 + (uint) (unsigned char) (*str - '0');
579
579
    }
580
580
    if (field_length > 0)
581
581
      value*= (long) log_10_int[field_length];
727
727
    Year between 1970-2069
728
728
*/
729
729
 
730
 
uint year_2000_handling(uint year)
 
730
uint32_t year_2000_handling(uint32_t year)
731
731
{
732
732
  if ((year=year+1900) < 1900+YY_PART_YEAR)
733
733
    year+=100;
750
750
    Days since 0000-00-00
751
751
*/
752
752
 
753
 
long calc_daynr(uint year,uint month,uint day)
 
753
long calc_daynr(uint32_t year,uint32_t month,uint32_t day)
754
754
{
755
755
  long delsum;
756
756
  int temp;
793
793
my_system_gmt_sec(const DRIZZLE_TIME *t_src, long *my_timezone,
794
794
                  bool *in_dst_time_gap)
795
795
{
796
 
  uint loop;
 
796
  uint32_t loop;
797
797
  time_t tmp= 0;
798
798
  int shift= 0;
799
799
  DRIZZLE_TIME tmp_time;
1003
1003
 
1004
1004
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to)
1005
1005
{
1006
 
  uint extra_hours= 0;
 
1006
  uint32_t extra_hours= 0;
1007
1007
  return sprintf(to, "%s%02u:%02u:%02u",
1008
1008
                         (l_time->neg ? "-" : ""),
1009
1009
                         extra_hours+ l_time->hour,
1089
1089
*/
1090
1090
 
1091
1091
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
1092
 
                            uint flags, int *was_cut)
 
1092
                            uint32_t flags, int *was_cut)
1093
1093
{
1094
1094
  long part1,part2;
1095
1095