1 #ifndef TZTIME_INCLUDED 2 #define TZTIME_INCLUDED 3 4 /* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License, version 2.0, 8 as published by the Free Software Foundation. 9 10 This program is also distributed with certain software (including 11 but not limited to OpenSSL) that is licensed under separate terms, 12 as designated in a particular file or component or in included license 13 documentation. The authors of MySQL hereby grant you an additional 14 permission to link the program and your derivative works with the 15 separately licensed software that they have included with MySQL. 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 Foundation, 24 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 25 26 27 #include "my_time.h" /* my_time_t */ 28 #include "mysql_time.h" /* MYSQL_TIME */ 29 #include "sql_alloc.h" 30 #include "sql_string.h" /* String */ 31 32 class THD; 33 34 #if !defined(TESTTIME) && !defined(TZINFO2SQL) 35 36 class THD; 37 38 /** 39 This class represents abstract time zone and provides 40 basic interface for MYSQL_TIME <-> my_time_t conversion. 41 Actual time zones which are specified by DB, or via offset 42 or use system functions are its descendants. 43 */ 44 class Time_zone: public Sql_alloc 45 { 46 public: Time_zone()47 Time_zone() {} /* Remove gcc warning */ 48 /** 49 Converts local time in broken down MYSQL_TIME representation to 50 my_time_t (UTC seconds since Epoch) represenation. 51 Returns 0 in case of error. Sets in_dst_time_gap to true if date provided 52 falls into spring time-gap (or lefts it untouched otherwise). 53 */ 54 virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t, 55 my_bool *in_dst_time_gap) const = 0; 56 /** 57 Converts time in my_time_t representation to local time in 58 broken down MYSQL_TIME representation. 59 */ 60 virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0; 61 /** 62 Comverts "struct timeval" to local time in 63 broken down MYSQL_TIME represendation. 64 */ gmt_sec_to_TIME(MYSQL_TIME * tmp,struct timeval tv)65 void gmt_sec_to_TIME(MYSQL_TIME *tmp, struct timeval tv) 66 { 67 gmt_sec_to_TIME(tmp, (my_time_t) tv.tv_sec); 68 tmp->second_part= tv.tv_usec; 69 } 70 /** 71 Because of constness of String returned by get_name() time zone name 72 have to be already zeroended to be able to use String::ptr() instead 73 of c_ptr(). 74 */ 75 virtual const String * get_name() const = 0; 76 77 /** 78 We need this only for surpressing warnings, objects of this type are 79 allocated on MEM_ROOT and should not require destruction. 80 */ ~Time_zone()81 virtual ~Time_zone() {}; 82 83 protected: 84 static inline void adjust_leap_second(MYSQL_TIME *t); 85 }; 86 87 extern Time_zone * my_tz_UTC; 88 extern Time_zone * my_tz_SYSTEM; 89 extern Time_zone * my_tz_OFFSET0; 90 extern Time_zone * my_tz_find(THD *thd, const String *name); 91 extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap); 92 extern void my_tz_free(); 93 extern my_time_t sec_since_epoch_TIME(MYSQL_TIME *t); 94 95 /** 96 Number of elements in table list produced by my_tz_get_table_list() 97 (this table list contains tables which are needed for dynamical loading 98 of time zone descriptions). Actually it is imlementation detail that 99 should not be used anywhere outside of tztime.h and tztime.cc. 100 */ 101 102 static const int MY_TZ_TABLES_COUNT= 4; 103 104 105 #endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */ 106 #endif /* TZTIME_INCLUDED */ 107