MySQL 8.0.39
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, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
17 the program or referenced in the documentation.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License, version 2.0, for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
27
28#include "my_inttypes.h"
29
30#ifdef HAVE_SYS_TIME_H
31#include <sys/time.h>
32#endif
33#ifdef _WIN32
34#include <winsock2.h>
35#endif
36
37#include "my_time_t.h" // my_time_t
38#include "mysql_time.h" // MYSQL_TIME
39
40class String;
41class THD;
42
43/**
44 This class represents abstract time zone and provides
45 basic interface for MYSQL_TIME <-> my_time_t conversion.
46 Actual time zones which are specified by DB, or via offset
47 or use system functions are its descendants.
48*/
49class Time_zone {
50 public:
51 /**
52 Enum to identify the type of the timezone
53 */
54 enum tz_type { TZ_DB = 1, TZ_OFFSET = 2, TZ_SYSTEM = 3, TZ_UTC = 4 };
55
56 /**
57 Converts local time in MYSQL_TIME representation to
58 my_time_t (UTC seconds since Epoch) representation.
59 Returns 0 in case of error. Sets in_dst_time_gap to true if date provided
60 falls into spring time-gap (or lefts it untouched otherwise).
61 */
63 bool *in_dst_time_gap) const = 0;
64 /**
65 Converts UTC epoch seconds to time in MYSQL_TIME representation.
66
67 @param[out] tmp equivalent time point in MYSQL_TIME representation
68 @param[in] t number of seconds in UNIX epoch
69 */
70 virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0;
71 /**
72 Converts UTC epoch seconds and microseconds to time in
73 MYSQL_TIME representation.
74
75 @param[in] tv number of seconds and microseconds in UNIX epoch
76 @param[out] tmp equivalent time point in MYSQL_TIME representation
77 */
78 void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_timeval tv) const {
80 tmp->second_part = tv.m_tv_usec;
81 }
82 /**
83 Because of constness of String returned by get_name() time zone name
84 have to be already zeroended to be able to use String::ptr() instead
85 of c_ptr().
86 */
87 virtual const String *get_name() const = 0;
88 /**
89 *Returns the timezone type set.
90 */
91 virtual tz_type get_timezone_type() const = 0;
92 /**
93 Returns the offset set for a Timezone offset.
94 This function has to be invoked ONLY when TZ_OFFSET is set.
95 */
96 virtual long get_timezone_offset() const = 0;
97 /**
98 We need this only for suppressing warnings, objects of this type are
99 allocated on MEM_ROOT and should not require destruction.
100 */
101 virtual ~Time_zone() = default;
102
103 protected:
104 static inline void adjust_leap_second(MYSQL_TIME *t);
105};
106
107extern Time_zone *my_tz_UTC;
108extern Time_zone *my_tz_SYSTEM;
110extern Time_zone *my_tz_find(THD *thd, const String *name);
111extern bool my_tz_init(THD *org_thd, const char *default_tzname,
112 bool bootstrap);
113extern void my_tz_free();
115
118my_time_t use_input_time_zone(const MYSQL_TIME *input, bool *in_dst_time_gap);
119void sec_to_TIME(MYSQL_TIME *tmp, my_time_t t, int64 offset);
120
121/**
122 Number of elements in table list produced by my_tz_get_table_list()
123 (this table list contains tables which are needed for dynamical loading
124 of time zone descriptions). Actually it is implementation detail that
125 should not be used anywhere outside of tztime.h and tztime.cc.
126*/
127
128static const int MY_TZ_TABLES_COUNT = 4;
129
130#endif /* TZTIME_INCLUDED */
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:49
void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_timeval tv) const
Converts UTC epoch seconds and microseconds to time in MYSQL_TIME representation.
Definition: tztime.h:78
virtual ~Time_zone()=default
We need this only for suppressing warnings, objects of this type are allocated on MEM_ROOT and should...
static void adjust_leap_second(MYSQL_TIME *t)
Convert leap seconds into non-leap.
Definition: tztime.cc:1867
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 ...
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t, bool *in_dst_time_gap) const =0
Converts local time in MYSQL_TIME representation to my_time_t (UTC seconds since Epoch) representatio...
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const =0
Converts UTC epoch seconds to time in MYSQL_TIME representation.
tz_type
Enum to identify the type of the timezone.
Definition: tztime.h:54
@ TZ_UTC
Definition: tztime.h:54
@ TZ_SYSTEM
Definition: tztime.h:54
@ TZ_DB
Definition: tztime.h:54
@ TZ_OFFSET
Definition: tztime.h:54
virtual long get_timezone_offset() const =0
Returns the offset set for a Timezone offset.
virtual tz_type get_timezone_type() const =0
Returns the timezone type set.
Some integer typedefs for easier portability.
int64_t int64
Definition: my_inttypes.h:68
int64_t my_time_t
Portable time_t replacement.
Definition: my_time_t.h:32
Time declarations shared between the server and client API: you should not add anything to this heade...
Definition: bootstrap.cc:70
case opt name
Definition: sslopt-case.h:33
Definition: mysql_time.h:82
unsigned long second_part
microseconds
Definition: mysql_time.h:84
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
int64_t m_tv_sec
Definition: my_time_t.h:46
int64_t m_tv_usec
Definition: my_time_t.h:47
Include file for Sun RPC to compile out of the box.
my_time_t use_input_time_zone(const MYSQL_TIME *input, bool *in_dst_time_gap)
void sec_to_TIME(MYSQL_TIME *tmp, my_time_t t, int64 offset)
Definition: tztime.cc:132
bool my_tz_init(THD *org_thd, const char *default_tzname, bool bootstrap)
Definition: tztime.cc:1186
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:611
Time_zone * my_tz_UTC
Definition: tztime.cc:1036
Time_zone * my_tz_find(THD *thd, const String *name)
Get Time_zone object for specified time zone.
Definition: tztime.cc:1804
void my_tz_free()
Definition: tztime.cc:1354
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:582
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:128
Time_zone * my_tz_OFFSET0
Definition: tztime.cc:1035
my_time_t sec_since_epoch_TIME(MYSQL_TIME *t)
Time_zone * my_tz_SYSTEM
Definition: tztime.cc:1037