MySQL  8.0.23
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, 2020, 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 #include "my_inttypes.h"
28 
29 #ifdef HAVE_SYS_TIME_H
30 #include <sys/time.h>
31 #endif
32 #ifdef _WIN32
33 #include <winsock2.h>
34 #endif
35 
36 #include "mysql_time.h" // MYSQL_TIME
37 #include "time_zone_common.h" // my_time_t
38 
39 class String;
40 class THD;
41 
42 /**
43  This class represents abstract time zone and provides
44  basic interface for MYSQL_TIME <-> my_time_t conversion.
45  Actual time zones which are specified by DB, or via offset
46  or use system functions are its descendants.
47 */
48 class Time_zone {
49  public:
50  /**
51  Converts local time in broken down MYSQL_TIME representation to
52  my_time_t (UTC seconds since Epoch) represenation.
53  Returns 0 in case of error. Sets in_dst_time_gap to true if date provided
54  falls into spring time-gap (or lefts it untouched otherwise).
55  */
57  bool *in_dst_time_gap) const = 0;
58  /**
59  Converts time in my_time_t representation to local time in
60  broken down MYSQL_TIME representation.
61  */
62  virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0;
63  /**
64  Comverts "struct timeval" to local time in
65  broken down MYSQL_TIME represendation.
66  */
67  void gmt_sec_to_TIME(MYSQL_TIME *tmp, struct timeval tv) const {
68  gmt_sec_to_TIME(tmp, (my_time_t)tv.tv_sec);
69  tmp->second_part = tv.tv_usec;
70  }
71  /**
72  Because of constness of String returned by get_name() time zone name
73  have to be already zeroended to be able to use String::ptr() instead
74  of c_ptr().
75  */
76  virtual const String *get_name() const = 0;
77 
78  /**
79  We need this only for surpressing warnings, objects of this type are
80  allocated on MEM_ROOT and should not require destruction.
81  */
82  virtual ~Time_zone() = default;
83 
84  protected:
85  static inline void adjust_leap_second(MYSQL_TIME *t);
86 };
87 
88 extern Time_zone *my_tz_UTC;
89 extern Time_zone *my_tz_SYSTEM;
90 extern Time_zone *my_tz_OFFSET0;
91 extern Time_zone *my_tz_find(THD *thd, const String *name);
92 extern bool my_tz_init(THD *org_thd, const char *default_tzname,
93  bool bootstrap);
94 extern void my_tz_free();
96 
99 my_time_t use_input_time_zone(const MYSQL_TIME *input, bool *in_dst_time_gap);
100 void sec_to_TIME(MYSQL_TIME *tmp, my_time_t t, int64 offset);
101 
102 /**
103  Number of elements in table list produced by my_tz_get_table_list()
104  (this table list contains tables which are needed for dynamical loading
105  of time zone descriptions). Actually it is imlementation detail that
106  should not be used anywhere outside of tztime.h and tztime.cc.
107 */
108 
109 static const int MY_TZ_TABLES_COUNT = 4;
110 
111 #endif /* TZTIME_INCLUDED */
THD
Definition: sql_class.h:807
MYSQL_TIME::second_part
unsigned long second_part
microseconds
Definition: mysql_time.h:83
bootstrap
Definition: bootstrap.cc:68
String
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:164
MY_TZ_TABLES_COUNT
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:109
my_time_t
[] long int my_time_t
Portable time_t replacement.
name
case opt name
Definition: sslopt-case.h:32
my_tz_free
void my_tz_free()
Definition: tztime.cc:1321
use_input_time_zone
my_time_t use_input_time_zone(const MYSQL_TIME *input, bool *in_dst_time_gap)
Time_zone::~Time_zone
virtual ~Time_zone()=default
We need this only for surpressing warnings, objects of this type are allocated on MEM_ROOT and should...
my_tz_init
bool my_tz_init(THD *org_thd, const char *default_tzname, bool bootstrap)
Definition: tztime.cc:1153
my_tz_SYSTEM
Time_zone * my_tz_SYSTEM
Definition: tztime.cc:1004
Time_zone::adjust_leap_second
static void adjust_leap_second(MYSQL_TIME *t)
Convert leap seconds into non-leap.
Definition: tztime.cc:1834
my_config.h
int64
int64_t int64
Definition: my_inttypes.h:67
Time_zone::get_name
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 ...
my_inttypes.h
my_tz_UTC
Time_zone * my_tz_UTC
Definition: tztime.cc:1003
time.h
Time_zone::gmt_sec_to_TIME
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.
sec_since_epoch_TIME
my_time_t sec_since_epoch_TIME(MYSQL_TIME *t)
Time_zone::TIME_to_gmt_sec
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
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:48
MYSQL_TIME
Definition: mysql_time.h:81
sec_to_TIME
void sec_to_TIME(MYSQL_TIME *tmp, my_time_t t, int64 offset)
Definition: tztime.cc:130
convert_time_zone_displacement
bool convert_time_zone_displacement(const Time_zone *tz, MYSQL_TIME *mt)
Converts a date/time value with time zone to the corresponding date/time value without time zone,...
Definition: tztime.cc:617
Time_zone::gmt_sec_to_TIME
void gmt_sec_to_TIME(MYSQL_TIME *tmp, struct timeval tv) const
Comverts "struct timeval" to local time in broken down MYSQL_TIME represendation.
Definition: tztime.h:67
check_time_zone_convertibility
bool check_time_zone_convertibility(const MYSQL_TIME &mt)
Checks that this temporal value can be converted from its specified time zone (if any) to the current...
Definition: tztime.cc:588
time_zone_common.h
my_tz_OFFSET0
Time_zone * my_tz_OFFSET0
Definition: tztime.cc:1002
my_tz_find
Time_zone * my_tz_find(THD *thd, const String *name)
Get Time_zone object for specified time zone.
Definition: tztime.cc:1771
mysql_time.h