From e9fd5301c4506f2080fb56096c9e2862ebb2bad2 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Wed, 14 Mar 2012 09:23:21 -0400 Subject: [PATCH] API: lib: renamed TimeZone to StaticTimeZone, along with API functions The StaticTimeZone data is hard coded in the library, so makes sense to name it that way explicitly, and let the record class use TimeZone instead of the odd Timezone/TimeZone mix we had before. --- src/r_calendar.cc | 4 ++-- src/r_task.cc | 4 ++-- src/time.cc | 36 ++++++++++++++++++------------------ src/time.h | 20 ++++++++++++++------ 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/r_calendar.cc b/src/r_calendar.cc index 7965b97b..a4d3e0ce 100644 --- a/src/r_calendar.cc +++ b/src/r_calendar.cc @@ -405,7 +405,7 @@ void Calendar::Clear() CalendarID = btohll((uint64_t) -1); - TimeZoneCode = GetTimeZoneCode(0, 0); // default to GMT + TimeZoneCode = GetStaticTimeZoneCode(0, 0); // default to GMT TimeZoneValid = false; Unknowns.clear(); @@ -484,7 +484,7 @@ void Calendar::DumpSpecialFields(std::ostream &os) const os << " Class: " << ClassTypes[ClassFlag] << "\n"; os << " Free/Busy: " << FreeBusy[FreeBusyFlag] << "\n"; if( TimeZoneValid ) - os << " Time Zone: " << GetTimeZone(TimeZoneCode)->Name << "\n"; + os << " Time Zone: " << GetStaticTimeZone(TimeZoneCode)->Name << "\n"; } void Calendar::Dump(std::ostream &os) const diff --git a/src/r_task.cc b/src/r_task.cc index 1d2bd023..361eb19f 100644 --- a/src/r_task.cc +++ b/src/r_task.cc @@ -343,7 +343,7 @@ void Task::Clear() DueTime.clear(); AlarmTime.clear(); - TimeZoneCode = GetTimeZoneCode( 0, 0 ); // default to GMT + TimeZoneCode = GetStaticTimeZoneCode( 0, 0 ); // default to GMT TimeZoneValid = false; AlarmType = (AlarmFlagType)0; @@ -452,7 +452,7 @@ void Task::Dump(std::ostream &os) const os << " Alarm Type: " << AlarmTypeName[AlarmType] << "\n"; } if( TimeZoneValid ) - os << " Time Zone: " << GetTimeZone(TimeZoneCode)->Name << "\n"; + os << " Time Zone: " << GetStaticTimeZone(TimeZoneCode)->Name << "\n"; // print recurrence data if available os << " Recurring: " << (Recurring ? "yes" : "no") << "\n"; diff --git a/src/time.cc b/src/time.cc index d981c1fa..67f27bd0 100644 --- a/src/time.cc +++ b/src/time.cc @@ -28,7 +28,7 @@ namespace Barry { -TimeZone Zones[] = { +StaticTimeZone Zones[] = { { 0x0000, -12, 0, "Eniwetok, Kwajalein (-12)" }, { 0x0001, -12, 0, "Midway Island, Samoa (-12)" }, { 0x0002, -10, 0, "Hawaii (-10)" }, @@ -126,32 +126,32 @@ time_t min2time(min1900_t m) // -// GetTimeZoneTable +// GetStaticTimeZoneTable // -/// Returns a pointer to an array of TimeZone structs. +/// Returns a pointer to an array of StaticTimeZone structs. /// The last struct contains 0 in all fields, and can be used as /// an "end of array" marker. /// -const TimeZone* GetTimeZoneTable() +const StaticTimeZone* GetStaticTimeZoneTable() { return Zones; } // -// GetTimeZone +// GetStaticTimeZone // /// Searches the internal timezone code table for the given Code -/// and returns a pointer to a TimeZone struct found. If the -/// code is not found, a pointer to a valid TimeZone struct is -/// is still returned, but the struct's Code contains TIME_ZONE_CODE_ERR, +/// and returns a pointer to a StaticTimeZone struct found. If the +/// code is not found, a pointer to a valid StaticTimeZone struct is +/// is still returned, but the struct's Code contains STATIC_TIME_ZONE_CODE_ERR, /// and the name is "Unknown time zone." The unknown timezone /// is the same offset as GMT. /// -const TimeZone* GetTimeZone(uint16_t Code) +const StaticTimeZone* GetStaticTimeZone(uint16_t Code) { - static TimeZone Unknown = { TIME_ZONE_CODE_ERR, 0, 0, "Unknown time zone" }; + static StaticTimeZone Unknown = { STATIC_TIME_ZONE_CODE_ERR, 0, 0, "Unknown time zone" }; - for( TimeZone *z = Zones; z->Name; z++ ) { + for( StaticTimeZone *z = Zones; z->Name; z++ ) { if( Code == z->Code ) return z; } @@ -159,21 +159,21 @@ const TimeZone* GetTimeZone(uint16_t Code) } // -// GetTimeZoneCode +// GetStaticTimeZoneCode // /// Searches the internal timezone table for the first matching -/// Code. If no matching Code is found, TIME_ZONE_CODE_ERR is returned. +/// Code. If no matching Code is found, STATIC_TIME_ZONE_CODE_ERR is returned. /// /// This function does not adjust for daylight saving time. /// -uint16_t GetTimeZoneCode(signed short HourOffset, +uint16_t GetStaticTimeZoneCode(signed short HourOffset, signed short MinOffset) { - for( TimeZone *z = Zones; z->Name; z++ ) { + for( StaticTimeZone *z = Zones; z->Name; z++ ) { if( HourOffset == z->HourOffset && MinOffset == z->MinOffset ) return z->Code; } - return TIME_ZONE_CODE_ERR; + return STATIC_TIME_ZONE_CODE_ERR; } /// This routine takes the day of the year and @@ -322,8 +322,8 @@ int main() cout << "Failed!" << endl; // time zone - cout << "Should say Eastern: " << GetTimeZone(0x23)->Name << endl; - cout << "should say Unknown: " << GetTimeZone(0xffff)->Name << endl; + cout << "Should say Eastern: " << GetStaticTimeZone(0x23)->Name << endl; + cout << "should say Unknown: " << GetStaticTimeZone(0xffff)->Name << endl; } #endif diff --git a/src/time.h b/src/time.h index b2a7a0ad..a1e9ef81 100644 --- a/src/time.h +++ b/src/time.h @@ -53,9 +53,17 @@ typedef long min1900_t; BXEXPORT min1900_t time2min(time_t t); BXEXPORT time_t min2time(min1900_t m); -// FIXME - turn TimeZone into a C typedef and wrap this in extern "C" +// FIXME - turn StaticTimeZone into a C typedef and wrap this in extern "C" // so the data can be used in both C and C++ libraries -struct BXEXPORT TimeZone +// +// This is named StaticTimeZone since the time zone table is hard coded +// in the library. If you want to know what the device's idea of time zones +// is, then extract the time zone database using the TimeZone record class. +// +// See also the TimeZones class, which unifies access to the static and +// dynamic time zone tables in one class API. +// +struct BXEXPORT StaticTimeZone { uint16_t Code; signed short HourOffset; @@ -64,11 +72,11 @@ struct BXEXPORT TimeZone }; // FIXME - put this somewhere for both C and C++ -#define TIME_ZONE_CODE_ERR 0xffff +#define STATIC_TIME_ZONE_CODE_ERR 0xffff -BXEXPORT const TimeZone* GetTimeZoneTable(); -BXEXPORT const TimeZone* GetTimeZone(uint16_t Code); -BXEXPORT unsigned short GetTimeZoneCode(signed short HourOffset, +BXEXPORT const StaticTimeZone* GetStaticTimeZoneTable(); +BXEXPORT const StaticTimeZone* GetStaticTimeZone(uint16_t Code); +BXEXPORT unsigned short GetStaticTimeZoneCode(signed short HourOffset, signed short MinOffset = 0); // Message time conversion stuff -- 2.11.4.GIT