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