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