1#ifndef TZTIME_INCLUDED
2#define TZTIME_INCLUDED
3
4/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
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#ifdef USE_PRAGMA_INTERFACE
21#pragma interface /* gcc class interface */
22#endif
23
24#include "my_time.h" /* my_time_t */
25#include "mysql_time.h" /* MYSQL_TIME */
26#include "sql_list.h" /* Sql_alloc */
27#include "sql_string.h" /* String */
28
29class THD;
30
31#if !defined(TESTTIME) && !defined(TZINFO2SQL)
32
33class THD;
34
35/**
36 This class represents abstract time zone and provides
37 basic interface for MYSQL_TIME <-> my_time_t conversion.
38 Actual time zones which are specified by DB, or via offset
39 or use system functions are its descendants.
40*/
41class Time_zone: public Sql_alloc
42{
43public:
44 Time_zone() {} /* Remove gcc warning */
45 /**
46 Converts local time in broken down MYSQL_TIME representation to
47 my_time_t (UTC seconds since Epoch) represenation.
48 Returns 0 in case of error. May set error_code to ER_WARN_DATA_OUT_OF_RANGE
49 or ER_WARN_INVALID_TIMESTAMP, see TIME_to_timestamp())
50 */
51 virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
52 uint *error_code) const = 0;
53 /**
54 Converts time in my_time_t representation to local time in
55 broken down MYSQL_TIME representation.
56 */
57 virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0;
58 /**
59 Because of constness of String returned by get_name() time zone name
60 have to be already zeroended to be able to use String::ptr() instead
61 of c_ptr().
62 */
63 virtual const String * get_name() const = 0;
64
65 /**
66 We need this only for surpressing warnings, objects of this type are
67 allocated on MEM_ROOT and should not require destruction.
68 */
69 virtual ~Time_zone() {};
70
71protected:
72 static inline void adjust_leap_second(MYSQL_TIME *t);
73};
74
75extern Time_zone * my_tz_UTC;
76extern Time_zone * my_tz_SYSTEM;
77extern Time_zone * my_tz_OFFSET0;
78extern Time_zone * my_tz_find(THD *thd, const String *name);
79extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap);
80extern void my_tz_free();
81extern my_time_t sec_since_epoch_TIME(MYSQL_TIME *t);
82
83/**
84 Number of elements in table list produced by my_tz_get_table_list()
85 (this table list contains tables which are needed for dynamical loading
86 of time zone descriptions). Actually it is imlementation detail that
87 should not be used anywhere outside of tztime.h and tztime.cc.
88*/
89
90static const int MY_TZ_TABLES_COUNT= 4;
91
92#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
93#endif /* TZTIME_INCLUDED */
94