summaryrefslogtreecommitdiff
path: root/include/my_time.h
diff options
context:
space:
mode:
authorunknown <petr/cps@owlet.local>2006-11-01 18:18:01 +0300
committerunknown <petr/cps@owlet.local>2006-11-01 18:18:01 +0300
commit60e315c53d60d1337f71405472189bb353100237 (patch)
tree7a5f2fe23939ea4eb1a8b2fdd922f3d3a91fb230 /include/my_time.h
parent3ce0cadd05e00b31934af0bbf3b1f18891404a8e (diff)
parentb2c40c169869f7df93342b434b84af4fb26acbe2 (diff)
downloadmariadb-git-60e315c53d60d1337f71405472189bb353100237.tar.gz
Merge mysql.com:/home/cps/mysql/trees/5.0-runtime-bug9191
into mysql.com:/home/cps/mysql/trees/5.1-runtime-bug9191 configure.in: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/timezone2.result: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/timezone2.test: Auto merged sql/item_timefunc.cc: Auto merged sql-common/my_time.c: Auto merged sql/mysql_priv.h: Auto merged sql/time.cc: Auto merged sql/tztime.cc: Auto merged include/my_time.h: manual merge
Diffstat (limited to 'include/my_time.h')
-rw-r--r--include/my_time.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/my_time.h b/include/my_time.h
index 6f053e71000..dbe608cc8e2 100644
--- a/include/my_time.h
+++ b/include/my_time.h
@@ -43,6 +43,12 @@ typedef long my_time_t;
#define MY_TIME_T_MAX LONG_MAX
#define MY_TIME_T_MIN LONG_MIN
+/* Time handling defaults */
+#define TIMESTAMP_MAX_YEAR 2038
+#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
+#define TIMESTAMP_MAX_VALUE INT_MAX32
+#define TIMESTAMP_MIN_VALUE 1
+
/* two-digit years < this are 20..; >= this are 19.. */
#define YY_PART_YEAR 70
/* apply above magic to years < this */
@@ -76,6 +82,30 @@ uint calc_days_in_year(uint year);
void init_time(void);
+
+/*
+ Function to check sanity of a TIMESTAMP value
+
+ DESCRIPTION
+ Check if a given MYSQL_TIME value fits in TIMESTAMP range.
+ This function doesn't make precise check, but rather a rough
+ estimate.
+
+ RETURN VALUES
+ FALSE The value seems sane
+ TRUE The MYSQL_TIME value is definitely out of range
+*/
+
+static inline bool validate_timestamp_range(const MYSQL_TIME *t)
+{
+ if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
+ (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
+ (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
+ return FALSE;
+
+ return TRUE;
+}
+
my_time_t
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone,
my_bool *in_dst_time_gap);