~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
#include <cstdio>
23
 
#include <drizzled/tztime.h>
24
 
#include <drizzled/gettext.h>
25
 
#include <drizzled/session.h>
26
 
#include <drizzled/time_functions.h>
 
23
#include "drizzled/tzfile.h"
 
24
#include "drizzled/tztime.h"
 
25
#include "drizzled/gettext.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/time_functions.h"
27
28
 
28
29
namespace drizzled
29
30
{
48
49
{
49
50
public:
50
51
  Time_zone_system() {}                       /* Remove gcc warning */
51
 
  virtual type::Time::epoch_t TIME_to_gmt_sec(const type::Time &t,
52
 
                                              bool *in_dst_time_gap) const;
53
 
  virtual void gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_t t) const;
 
52
  virtual time_t TIME_to_gmt_sec(const type::Time *t,
 
53
                                    bool *in_dst_time_gap) const;
 
54
  virtual void gmt_sec_to_TIME(type::Time *tmp, time_t t) const;
54
55
  virtual const String * get_name() const;
55
56
};
56
57
 
58
59
/**
59
60
 * @brief
60
61
 * Converts local time in system time zone in type::Time representation
61
 
 * to its type::Time::epoch_t representation.
 
62
 * to its time_t representation.
62
63
 *
63
64
 * @details
64
65
 * This method uses system function (localtime_r()) for conversion
65
 
 * local time in system time zone in type::Time structure to its type::Time::epoch_t
 
66
 * local time in system time zone in type::Time structure to its time_t
66
67
 * representation. Unlike the same function for Time_zone_db class
67
68
 * it it won't handle unnormalized input properly. Still it will
68
 
 * return lowest possible type::Time::epoch_t in case of ambiguity or if we
 
69
 * return lowest possible time_t in case of ambiguity or if we
69
70
 * provide time corresponding to the time-gap.
70
71
 *
71
72
 * You should call init_time() function before using this function.
77
78
 *                          spring time-gap) and is not touched otherwise.
78
79
 *
79
80
 * @return
80
 
 * Corresponding type::Time::epoch_t value or 0 in case of error
 
81
 * Corresponding time_t value or 0 in case of error
81
82
 */
82
 
type::Time::epoch_t
83
 
Time_zone_system::TIME_to_gmt_sec(const type::Time &t, bool *in_dst_time_gap) const
 
83
time_t
 
84
Time_zone_system::TIME_to_gmt_sec(const type::Time *t, bool *in_dst_time_gap) const
84
85
{
85
86
  long not_used;
86
 
  type::Time::epoch_t tmp;
87
 
  t.convert(tmp, &not_used, in_dst_time_gap);
88
 
  return tmp;
 
87
  return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
89
88
}
90
89
 
91
90
 
92
91
/**
93
92
 * @brief
94
 
 * Converts time from UTC seconds since Epoch (type::Time::epoch_t) representation
 
93
 * Converts time from UTC seconds since Epoch (time_t) representation
95
94
 * to system local time zone broken-down representation.
96
95
 *
97
96
 * @param    tmp   pointer to type::Time structure to fill-in
98
 
 * @param    t     type::Time::epoch_t value to be converted
 
97
 * @param    t     time_t value to be converted
99
98
 *
100
 
 * Note: We assume that value passed to this function will fit into type::Time::epoch_t range
 
99
 * Note: We assume that value passed to this function will fit into time_t range
101
100
 * supported by localtime_r. This conversion is putting restriction on
102
101
 * TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
103
102
 * for interaction with client then we can extend TIMESTAMP range down to
104
103
 * the 1902 easily.
105
104
 */
106
105
void
107
 
Time_zone_system::gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_t t) const
 
106
Time_zone_system::gmt_sec_to_TIME(type::Time *tmp, time_t t) const
108
107
{
109
 
  tmp.store(t);
 
108
  struct tm tmp_tm;
 
109
  time_t tmp_t= (time_t)t;
 
110
 
 
111
  localtime_r(&tmp_t, &tmp_tm);
 
112
  localtime_to_TIME(tmp, &tmp_tm);
 
113
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
110
114
}
111
115
 
112
116
 
127
131
 
128
132
Time_zone *my_tz_SYSTEM= &tz_SYSTEM;
129
133
 
 
134
 
 
135
/**
 
136
 * @brief
 
137
 * Initialize time zone support infrastructure.
 
138
 *
 
139
 * @details
 
140
 * This function will init memory structures needed for time zone support,
 
141
 * it will register mandatory SYSTEM time zone in them. It will try to open
 
142
 * mysql.time_zone* tables and load information about default time zone and
 
143
 * information which further will be shared among all time zones loaded.
 
144
 * If system tables with time zone descriptions don't exist it won't fail
 
145
 * (unless default_tzname is time zone from tables). If bootstrap parameter
 
146
 * is true then this routine assumes that we are in bootstrap mode and won't
 
147
 * load time zone descriptions unless someone specifies default time zone
 
148
 * which is supposedly stored in those tables.
 
149
 * It'll also set default time zone if it is specified.
 
150
 *
 
151
 * @param   session            current thread object
 
152
 * @param   default_tzname     default time zone or 0 if none.
 
153
 * @param   bootstrap          indicates whenever we are in bootstrap mode
 
154
 *
 
155
 * @return
 
156
 *  0 - ok
 
157
 *  1 - Error
 
158
 */
 
159
bool
 
160
my_tz_init(Session *session, const char *default_tzname)
 
161
{
 
162
  if (default_tzname)
 
163
  {
 
164
    String tmp_tzname2(default_tzname, &my_charset_utf8_general_ci);
 
165
    /*
 
166
      Time zone tables may be open here, and my_tz_find() may open
 
167
      most of them once more, but this is OK for system tables open
 
168
      for READ.
 
169
    */
 
170
    if (!(global_system_variables.time_zone= my_tz_find(session, &tmp_tzname2)))
 
171
    {
 
172
      errmsg_printf(ERRMSG_LVL_ERROR,
 
173
                    _("Fatal error: Illegal or unknown default time zone '%s'"),
 
174
                    default_tzname);
 
175
      return true;
 
176
    }
 
177
  }
 
178
 
 
179
  return false;
 
180
}
 
181
 
 
182
/**
 
183
 * @brief
 
184
 * Get Time_zone object for specified time zone.
 
185
 *
 
186
 * @todo
 
187
 * Not implemented yet. This needs to hook into some sort of OS system call.
 
188
 */
 
189
Time_zone *
 
190
my_tz_find(Session *,
 
191
           const String *)
 
192
{
 
193
  return NULL;
 
194
}
 
195
 
130
196
} /* namespace drizzled */