~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

move ATAN() and ATAN2() function into math_functions plugin. ATAN2() is just another instance of ATAN()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
49
49
{
50
50
public:
51
51
  Time_zone_system() {}                       /* Remove gcc warning */
52
 
  virtual type::Time::epoch_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, type::Time::epoch_t t) const;
 
52
  virtual time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
 
53
                                    bool *in_dst_time_gap) const;
 
54
  virtual void gmt_sec_to_TIME(DRIZZLE_TIME *tmp, time_t t) const;
55
55
  virtual const String * get_name() const;
56
56
};
57
57
 
58
58
 
59
59
/**
60
60
 * @brief
61
 
 * Converts local time in system time zone in type::Time representation
62
 
 * to its type::Time::epoch_t representation.
 
61
 * Converts local time in system time zone in DRIZZLE_TIME representation
 
62
 * to its time_t representation.
63
63
 *
64
64
 * @details
65
65
 * This method uses system function (localtime_r()) for conversion
66
 
 * local time in system time zone in type::Time structure to its type::Time::epoch_t
 
66
 * local time in system time zone in DRIZZLE_TIME structure to its time_t
67
67
 * representation. Unlike the same function for Time_zone_db class
68
68
 * it it won't handle unnormalized input properly. Still it will
69
 
 * 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
70
70
 * provide time corresponding to the time-gap.
71
71
 *
72
72
 * You should call init_time() function before using this function.
73
73
 *
74
 
 * @param   t               pointer to type::Time structure with local time in
 
74
 * @param   t               pointer to DRIZZLE_TIME structure with local time in
75
75
 *                          broken-down representation.
76
76
 * @param   in_dst_time_gap pointer to bool which is set to true if datetime
77
77
 *                          value passed doesn't really exist (i.e. falls into
78
78
 *                          spring time-gap) and is not touched otherwise.
79
79
 *
80
80
 * @return
81
 
 * Corresponding type::Time::epoch_t value or 0 in case of error
 
81
 * Corresponding time_t value or 0 in case of error
82
82
 */
83
 
type::Time::epoch_t
84
 
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 DRIZZLE_TIME *t, bool *in_dst_time_gap) const
85
85
{
86
86
  long not_used;
87
 
  type::Time::epoch_t tmp;
88
 
  t.convert(tmp, &not_used, in_dst_time_gap);
89
 
  return tmp;
 
87
  return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
90
88
}
91
89
 
92
90
 
93
91
/**
94
92
 * @brief
95
 
 * Converts time from UTC seconds since Epoch (type::Time::epoch_t) representation
 
93
 * Converts time from UTC seconds since Epoch (time_t) representation
96
94
 * to system local time zone broken-down representation.
97
95
 *
98
 
 * @param    tmp   pointer to type::Time structure to fill-in
99
 
 * @param    t     type::Time::epoch_t value to be converted
 
96
 * @param    tmp   pointer to DRIZZLE_TIME structure to fill-in
 
97
 * @param    t     time_t value to be converted
100
98
 *
101
 
 * 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
102
100
 * supported by localtime_r. This conversion is putting restriction on
103
101
 * TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
104
102
 * for interaction with client then we can extend TIMESTAMP range down to
105
103
 * the 1902 easily.
106
104
 */
107
105
void
108
 
Time_zone_system::gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_t t) const
 
106
Time_zone_system::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, time_t t) const
109
107
{
110
 
  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;
111
114
}
112
115
 
113
116
 
166
169
    */
167
170
    if (!(global_system_variables.time_zone= my_tz_find(session, &tmp_tzname2)))
168
171
    {
169
 
      errmsg_printf(error::ERROR,
 
172
      errmsg_printf(ERRMSG_LVL_ERROR,
170
173
                    _("Fatal error: Illegal or unknown default time zone '%s'"),
171
174
                    default_tzname);
172
175
      return true;