MySQL  8.0.27
Source Code Documentation
time_zone_common.h
Go to the documentation of this file.
1 #ifndef TIME_ZONE_COMMON_H
2 #define TIME_ZONE_COMMON_H
3 /* Copyright (c) 2004, 2021, Oracle and/or its affiliates.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation. The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24 
25 #include "my_alloc.h" // MEM_ROOT
26 
27 /**
28  @file
29  Contains common functionality shared between mysqld and
30  mysql_tz_info_to_sql.
31 */
32 
33 using my_time_t = long;
34 
35 /*
36  Now we don't use abbreviations in server but we will do this in future.
37 */
38 #if !defined(NDEBUG)
39 /* Let use abbreviations for debug purposes */
40 #undef ABBR_ARE_USED
41 #define ABBR_ARE_USED
42 #endif /* !defined(NDEBUG) */
43 
44 /* Structure describing local time type (e.g. Moscow summer time (MSD)) */
45 typedef struct ttinfo {
46  long tt_gmtoff; // Offset from UTC in seconds
47  unsigned tt_isdst; // Is daylight saving time or not. Used to set tm_isdst
48 #ifdef ABBR_ARE_USED
49  unsigned tt_abbrind; // Index of start of abbreviation for this time type.
50 #endif
51  /*
52  We don't use tt_ttisstd and tt_ttisgmt members of original elsie-code
53  struct since we don't support POSIX-style TZ descriptions in variables.
54  */
56 
57 /* Structure describing leap-second corrections. */
58 typedef struct lsinfo {
59  my_time_t ls_trans; // Transition time
60  long ls_corr; // Correction to apply
62 
63 /*
64  Structure with information describing ranges of my_time_t shifted to local
65  time (my_time_t + offset). Used for local MYSQL_TIME -> my_time_t conversion.
66  See comments for TIME_to_gmt_sec() for more info.
67 */
68 typedef struct revtinfo {
69  long rt_offset; // Offset of local time from UTC in seconds
70  unsigned rt_type; // Type of period 0 - Normal period. 1 - Spring time-gap
72 
73 #ifdef TZNAME_MAX
74 #define MY_TZNAME_MAX TZNAME_MAX
75 #endif
76 #ifndef TZNAME_MAX
77 #define MY_TZNAME_MAX 255
78 #endif
79 
80 /*
81  Structure which fully describes time zone which is
82  described in our db or in zoneinfo files.
83 */
85  unsigned leapcnt; // Number of leap-second corrections
86  unsigned timecnt; // Number of transitions between time types
87  unsigned typecnt; // Number of local time types
88  size_t charcnt; // Number of characters used for abbreviations
89  unsigned
90  revcnt; // Number of transition descr. for TIME->my_time_t conversion
91  /* The following are dynamical arrays are allocated in MEM_ROOT */
92  my_time_t *ats; // Times of transitions between time types
93  uchar *types; // Local time types for transitions
94  TRAN_TYPE_INFO *ttis; // Local time types descriptions
95 #ifdef ABBR_ARE_USED
96  /* Storage for local time types abbreviations. They are stored as ASCIIZ */
97  char *chars;
98 #endif
99  /*
100  Leap seconds corrections descriptions, this array is shared by
101  all time zones who use leap seconds.
102  */
104  /*
105  Starting points and descriptions of shifted my_time_t (my_time_t + offset)
106  ranges on which shifted my_time_t -> my_time_t mapping is linear or
107  undefined. Used for tm -> my_time_t conversion.
108  */
111  /*
112  Time type which is used for times smaller than first transition or if
113  there are no transitions at all.
114  */
116 };
117 
118 /*
119  Finish preparation of time zone description for use in TIME_to_gmt_sec()
120  and gmt_sec_to_TIME() functions.
121 
122  SYNOPSIS
123  prepare_tz_info()
124  sp - pointer to time zone description
125  storage - pointer to MEM_ROOT where arrays for map allocated
126 
127  DESCRIPTION
128  First task of this function is to find fallback time type which will
129  be used if there are no transitions or we have moment in time before
130  any transitions.
131  Second task is to build "shifted my_time_t" -> my_time_t map used in
132  MYSQL_TIME -> my_time_t conversion.
133  Note: See description of TIME_to_gmt_sec() function first.
134  In order to perform MYSQL_TIME -> my_time_t conversion we need to build
135  table which defines "shifted by tz offset and leap seconds my_time_t" ->
136  my_time_t function wich is almost the same (except ranges of ambiguity)
137  as reverse function to piecewise linear function used for my_time_t ->
138  "shifted my_time_t" conversion and which is also specified as table in
139  zoneinfo file or in our db (It is specified as start of time type ranges
140  and time type offsets). So basic idea is very simple - let us iterate
141  through my_time_t space from one point of discontinuity of my_time_t ->
142  "shifted my_time_t" function to another and build our approximation of
143  reverse function. (Actually we iterate through ranges on which
144  my_time_t -> "shifted my_time_t" is linear function).
145 
146  RETURN VALUES
147  0 Ok
148  1 Error
149 */
150 bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage);
151 
152 #endif // TIME_ZONE_COMMON_H
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
unsigned char uchar
Definition: my_inttypes.h:51
[] long int my_time_t
Portable time_t replacement.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: time_zone_common.h:84
unsigned revcnt
Definition: time_zone_common.h:90
size_t charcnt
Definition: time_zone_common.h:88
uchar * types
Definition: time_zone_common.h:93
TRAN_TYPE_INFO * fallback_tti
Definition: time_zone_common.h:115
REVT_INFO * revtis
Definition: time_zone_common.h:110
unsigned leapcnt
Definition: time_zone_common.h:85
char * chars
Definition: time_zone_common.h:97
my_time_t * revts
Definition: time_zone_common.h:109
unsigned timecnt
Definition: time_zone_common.h:86
LS_INFO * lsis
Definition: time_zone_common.h:103
unsigned typecnt
Definition: time_zone_common.h:87
my_time_t * ats
Definition: time_zone_common.h:92
TRAN_TYPE_INFO * ttis
Definition: time_zone_common.h:94
Definition: time_zone_common.h:58
long ls_corr
Definition: time_zone_common.h:60
my_time_t ls_trans
Definition: time_zone_common.h:59
Definition: time_zone_common.h:68
long rt_offset
Definition: time_zone_common.h:69
unsigned rt_type
Definition: time_zone_common.h:70
Definition: time_zone_common.h:45
unsigned tt_abbrind
Definition: time_zone_common.h:49
long tt_gmtoff
Definition: time_zone_common.h:46
unsigned tt_isdst
Definition: time_zone_common.h:47
struct revtinfo REVT_INFO
struct ttinfo TRAN_TYPE_INFO
bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage)
Definition: time_zone_common.cc:92
struct lsinfo LS_INFO