MySQL  8.0.17
Source Code Documentation
tztime.h
Go to the documentation of this file.
1 #ifndef TZTIME_INCLUDED
2 #define TZTIME_INCLUDED
3 
4 #include "my_config.h"
5 /* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License, version 2.0,
9  as published by the Free Software Foundation.
10 
11  This program is also distributed with certain software (including
12  but not limited to OpenSSL) that is licensed under separate terms,
13  as designated in a particular file or component or in included license
14  documentation. The authors of MySQL hereby grant you an additional
15  permission to link the program and your derivative works with the
16  separately licensed software that they have included with MySQL.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License, version 2.0, for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26 
27 typedef long my_time_t;
28 
29 #if !defined(TESTTIME) && !defined(TZINFO2SQL)
30 
31 #include "my_inttypes.h"
32 
33 #ifdef HAVE_SYS_TIME_H
34 #include <sys/time.h>
35 #endif
36 #ifdef _WIN32
37 #include <winsock2.h>
38 #endif
39 
40 #include "mysql_time.h" // MYSQL_TIME
41 
42 class String;
43 class THD;
44 
45 /**
46  This class represents abstract time zone and provides
47  basic interface for MYSQL_TIME <-> my_time_t conversion.
48  Actual time zones which are specified by DB, or via offset
49  or use system functions are its descendants.
50 */
51 class Time_zone {
52  public:
53  Time_zone() {} /* Remove gcc warning */
54  /**
55  Converts local time in broken down MYSQL_TIME representation to
56  my_time_t (UTC seconds since Epoch) represenation.
57  Returns 0 in case of error. Sets in_dst_time_gap to true if date provided
58  falls into spring time-gap (or lefts it untouched otherwise).
59  */
60  virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
61  bool *in_dst_time_gap) const = 0;
62  /**
63  Converts time in my_time_t representation to local time in
64  broken down MYSQL_TIME representation.
65  */
66  virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0;
67  /**
68  Comverts "struct timeval" to local time in
69  broken down MYSQL_TIME represendation.
70  */
71  void gmt_sec_to_TIME(MYSQL_TIME *tmp, struct timeval tv) {
72  gmt_sec_to_TIME(tmp, (my_time_t)tv.tv_sec);
73  tmp->second_part = tv.tv_usec;
74  }
75  /**
76  Because of constness of String returned by get_name() time zone name
77  have to be already zeroended to be able to use String::ptr() instead
78  of c_ptr().
79  */
80  virtual const String *get_name() const = 0;
81 
82  /**
83  We need this only for surpressing warnings, objects of this type are
84  allocated on MEM_ROOT and should not require destruction.
85  */
86  virtual ~Time_zone() {}
87 
88  protected:
89  static inline void adjust_leap_second(MYSQL_TIME *t);
90 };
91 
92 extern Time_zone *my_tz_UTC;
93 extern Time_zone *my_tz_SYSTEM;
94 extern Time_zone *my_tz_OFFSET0;
95 extern Time_zone *my_tz_find(THD *thd, const String *name);
96 extern bool my_tz_init(THD *org_thd, const char *default_tzname,
97  bool bootstrap);
98 extern void my_tz_free();
100 
101 /**
102  Number of elements in table list produced by my_tz_get_table_list()
103  (this table list contains tables which are needed for dynamical loading
104  of time zone descriptions). Actually it is imlementation detail that
105  should not be used anywhere outside of tztime.h and tztime.cc.
106 */
107 
108 static const int MY_TZ_TABLES_COUNT = 4;
109 
110 #endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
111 #endif /* TZTIME_INCLUDED */
unsigned long second_part
microseconds
Definition: mysql_time.h:66
Time_zone()
Definition: tztime.h:53
const string name("\ame\)
virtual ~Time_zone()
We need this only for surpressing warnings, objects of this type are allocated on MEM_ROOT and should...
Definition: tztime.h:86
Some integer typedefs for easier portability.
bool my_tz_init(THD *org_thd, const char *default_tzname, bool bootstrap)
Definition: tztime.cc:1491
long my_time_t
Definition: tztime.h:27
[] long int my_time_t
Portable time_t replacement.
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:51
void my_tz_free()
Definition: tztime.cc:1660
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const =0
Converts time in my_time_t representation to local time in broken down MYSQL_TIME representation...
static void adjust_leap_second(MYSQL_TIME *t)
Convert leap seconds into non-leap.
Definition: tztime.cc:2158
virtual const String * get_name() const =0
Because of constness of String returned by get_name() time zone name have to be already zeroended to ...
t
Definition: dbug_analyze.cc:147
Time_zone * my_tz_OFFSET0
Definition: tztime.cc:1356
Time_zone * my_tz_UTC
Definition: tztime.cc:1357
void gmt_sec_to_TIME(MYSQL_TIME *tmp, struct timeval tv)
Comverts "struct timeval" to local time in broken down MYSQL_TIME represendation. ...
Definition: tztime.h:71
Time_zone * my_tz_SYSTEM
Definition: tztime.cc:1358
Definition: mysql_time.h:64
Definition: bootstrap.cc:67
Time declarations shared between the server and client API: you should not add anything to this heade...
my_time_t sec_since_epoch_TIME(MYSQL_TIME *t)
static const int MY_TZ_TABLES_COUNT
Number of elements in table list produced by my_tz_get_table_list() (this table list contains tables ...
Definition: tztime.h:108
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t, bool *in_dst_time_gap) const =0
Converts local time in broken down MYSQL_TIME representation to my_time_t (UTC seconds since Epoch) r...
Time_zone * my_tz_find(THD *thd, const String *name)
Definition: tztime.cc:2098
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777