1
by Monty Taylor
Import upstream version 2010.03.1347 |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1.2.4
by Monty Taylor
Import upstream version 2010.12.06 |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
||
1.2.9
by Monty Taylor
Import upstream version 2011.03.11 |
21 |
#include <config.h> |
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
22 |
#include <cstdio> |
1.2.9
by Monty Taylor
Import upstream version 2011.03.11 |
23 |
#include <drizzled/tztime.h> |
24 |
#include <drizzled/gettext.h> |
|
25 |
#include <drizzled/session.h> |
|
26 |
#include <drizzled/time_functions.h> |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
27 |
|
28 |
namespace drizzled |
|
29 |
{
|
|
30 |
||
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
31 |
/**
|
32 |
* String with names of SYSTEM time zone.
|
|
33 |
*/
|
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
34 |
static const String tz_SYSTEM_name("SYSTEM", 6, &my_charset_utf8_general_ci); |
35 |
||
36 |
||
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
37 |
/**
|
38 |
* Instance of this class represents local time zone used on this system
|
|
39 |
* (specified by TZ environment variable or via any other system mechanism).
|
|
40 |
* It uses system functions (localtime_r, my_system_gmt_sec) for conversion
|
|
41 |
* and is always available. Because of this it is used by default - if there
|
|
42 |
* were no explicit time zone specified. On the other hand because of this
|
|
43 |
* conversion methods provided by this class is significantly slower and
|
|
44 |
* possibly less multi-threaded-friendly than corresponding Time_zone_db
|
|
45 |
* methods so the latter should be preffered there it is possible.
|
|
46 |
*/
|
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
47 |
class Time_zone_system : public Time_zone |
48 |
{
|
|
49 |
public: |
|
50 |
Time_zone_system() {} /* Remove gcc warning */ |
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
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; |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
54 |
virtual const String * get_name() const; |
55 |
};
|
|
56 |
||
57 |
||
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
58 |
/**
|
59 |
* @brief
|
|
11
by Monty Taylor
* Fixed missing build depends. |
60 |
* Converts local time in system time zone in type::Time representation
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
61 |
* to its type::Time::epoch_t representation.
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
62 |
*
|
63 |
* @details
|
|
64 |
* This method uses system function (localtime_r()) for conversion
|
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
65 |
* local time in system time zone in type::Time structure to its type::Time::epoch_t
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
66 |
* representation. Unlike the same function for Time_zone_db class
|
67 |
* it it won't handle unnormalized input properly. Still it will
|
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
68 |
* return lowest possible type::Time::epoch_t in case of ambiguity or if we
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
69 |
* provide time corresponding to the time-gap.
|
70 |
*
|
|
71 |
* You should call init_time() function before using this function.
|
|
72 |
*
|
|
11
by Monty Taylor
* Fixed missing build depends. |
73 |
* @param t pointer to type::Time structure with local time in
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
74 |
* broken-down representation.
|
75 |
* @param in_dst_time_gap pointer to bool which is set to true if datetime
|
|
76 |
* value passed doesn't really exist (i.e. falls into
|
|
77 |
* spring time-gap) and is not touched otherwise.
|
|
78 |
*
|
|
79 |
* @return
|
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
80 |
* Corresponding type::Time::epoch_t value or 0 in case of error
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
81 |
*/
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
82 |
type::Time::epoch_t |
83 |
Time_zone_system::TIME_to_gmt_sec(const type::Time &t, bool *in_dst_time_gap) const |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
84 |
{
|
85 |
long not_used; |
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
86 |
type::Time::epoch_t tmp; |
87 |
t.convert(tmp, ¬_used, in_dst_time_gap); |
|
88 |
return tmp; |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
89 |
}
|
90 |
||
91 |
||
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
92 |
/**
|
93 |
* @brief
|
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
94 |
* Converts time from UTC seconds since Epoch (type::Time::epoch_t) representation
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
95 |
* to system local time zone broken-down representation.
|
96 |
*
|
|
11
by Monty Taylor
* Fixed missing build depends. |
97 |
* @param tmp pointer to type::Time structure to fill-in
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
98 |
* @param t type::Time::epoch_t value to be converted
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
99 |
*
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
100 |
* Note: We assume that value passed to this function will fit into type::Time::epoch_t range
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
101 |
* supported by localtime_r. This conversion is putting restriction on
|
102 |
* TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
|
|
103 |
* for interaction with client then we can extend TIMESTAMP range down to
|
|
104 |
* the 1902 easily.
|
|
105 |
*/
|
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
106 |
void
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
107 |
Time_zone_system::gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_t t) const |
1
by Monty Taylor
Import upstream version 2010.03.1347 |
108 |
{
|
1.2.7
by Monty Taylor
Import upstream version 2011.02.09 |
109 |
tmp.store(t); |
1
by Monty Taylor
Import upstream version 2010.03.1347 |
110 |
}
|
111 |
||
112 |
||
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
113 |
/**
|
114 |
* @brief
|
|
115 |
* Get name of time zone
|
|
116 |
*
|
|
117 |
* @return
|
|
118 |
* Name of time zone as String
|
|
119 |
*/
|
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
120 |
const String * |
121 |
Time_zone_system::get_name() const |
|
122 |
{
|
|
123 |
return &tz_SYSTEM_name; |
|
124 |
}
|
|
125 |
||
126 |
static Time_zone_system tz_SYSTEM; |
|
127 |
||
128 |
Time_zone *my_tz_SYSTEM= &tz_SYSTEM; |
|
129 |
||
130 |
} /* namespace drizzled */ |