From 22a29a9b96698c43aee169a963a4dd22e7b92ee7 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 31 Jan 2012 02:56:52 -0500 Subject: [PATCH] lib: added safety check in Timezone ctor for negative minutes The Timezone record class always works with minutes as positive. If the user happens to enter a negative minutes in the ctor, this still works, but just do a quick flip first. Note that the hard coded TimeZone table in time.cc uses negative minutes, so this safety check makes sense. --- src/r_timezone.cc | 5 +++++ src/r_timezone.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/r_timezone.cc b/src/r_timezone.cc index 204ae664..1f34a020 100644 --- a/src/r_timezone.cc +++ b/src/r_timezone.cc @@ -73,6 +73,11 @@ Timezone::Timezone(int hours, int minutes) { Clear(); + // make sure that minutes are always positive, for our logic + if( minutes < 0 ) + minutes = -minutes; + + // calculate offset in total minutes UTCOffset = hours * 60; if( hours < 0 ) UTCOffset -= minutes; diff --git a/src/r_timezone.h b/src/r_timezone.h index 27f830a4..cab1aa57 100644 --- a/src/r_timezone.h +++ b/src/r_timezone.h @@ -70,12 +70,13 @@ public: /// Creates a new timezone based on utc_offset minutes. /// Use same semantics as UTCOffset. For example, a -3.5 hour - /// timezone would be constructed as: Timezone(-210) + /// timezone (which is west of UTC) would be constructed + /// as: Timezone(-210) explicit Timezone(int utc_offset); /// Creates a new timezone based on negative/positive hours, /// and positive minutes. For example, a -3.5 hour timezone - /// would be constructed as: Timezone(-3, 30) + /// (which is west of UTC) would be constructed as: Timezone(-3, 30) Timezone(int hours, int minutes); virtual ~Timezone(); -- 2.11.4.GIT