~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

  • Committer: Brian Aker
  • Date: 2009-07-09 19:49:32 UTC
  • mfrom: (1085.1.10 mordred)
  • Revision ID: brian@gaz-20090709194932-o90qfzgk9xem5di1
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1078
1078
 
1079
1079
 
1080
1080
/*
1081
 
  Parse string that specifies time zone as offset from UTC.
1082
 
 
1083
 
  SYNOPSIS
1084
 
    str_to_offset()
1085
 
      str    - pointer to string which contains offset
1086
 
      length - length of string
1087
 
      offset - out parameter for storing found offset in seconds.
1088
 
 
1089
 
  DESCRIPTION
1090
 
    This function parses string which contains time zone offset
1091
 
    in form similar to '+10:00' and converts found value to
1092
 
    seconds from UTC form (east is positive).
1093
 
 
1094
 
  RETURN VALUE
1095
 
    0 - Ok
1096
 
    1 - String doesn't contain valid time zone offset
1097
 
*/
1098
 
bool
1099
 
str_to_offset(const char *str, uint32_t length, long *offset)
1100
 
{
1101
 
  const char *end= str + length;
1102
 
  bool negative;
1103
 
  ulong number_tmp;
1104
 
  long offset_tmp;
1105
 
 
1106
 
  if (length < 4)
1107
 
    return 1;
1108
 
 
1109
 
  if (*str == '+')
1110
 
    negative= 0;
1111
 
  else if (*str == '-')
1112
 
    negative= 1;
1113
 
  else
1114
 
    return 1;
1115
 
  str++;
1116
 
 
1117
 
  number_tmp= 0;
1118
 
 
1119
 
  while (str < end && my_isdigit(&my_charset_utf8_general_ci, *str))
1120
 
  {
1121
 
    number_tmp= number_tmp*10 + *str - '0';
1122
 
    str++;
1123
 
  }
1124
 
 
1125
 
  if (str + 1 >= end || *str != ':')
1126
 
    return 1;
1127
 
  str++;
1128
 
 
1129
 
  offset_tmp = number_tmp * MINS_PER_HOUR; number_tmp= 0;
1130
 
 
1131
 
  while (str < end && my_isdigit(&my_charset_utf8_general_ci, *str))
1132
 
  {
1133
 
    number_tmp= number_tmp * 10 + *str - '0';
1134
 
    str++;
1135
 
  }
1136
 
 
1137
 
  if (str != end)
1138
 
    return 1;
1139
 
 
1140
 
  offset_tmp= (offset_tmp + number_tmp) * SECS_PER_MIN;
1141
 
 
1142
 
  if (negative)
1143
 
    offset_tmp= -offset_tmp;
1144
 
 
1145
 
  /*
1146
 
    Check if offset is in range prescribed by standard
1147
 
    (from -12:59 to 13:00).
1148
 
  */
1149
 
 
1150
 
  if (number_tmp > 59 || offset_tmp < -13 * SECS_PER_HOUR + 1 ||
1151
 
      offset_tmp > 13 * SECS_PER_HOUR)
1152
 
    return 1;
1153
 
 
1154
 
  *offset= offset_tmp;
1155
 
 
1156
 
  return 0;
1157
 
}
1158
 
 
1159
 
 
1160
 
/*
1161
1081
  Get Time_zone object for specified time zone.
1162
1082
 
1163
1083
  Not implemented yet. This needs to hook into some sort of OS system call.