GnuCash  4.8a-132-gcdaeb421d+
gnc-timezone.hpp
1 /********************************************************************\
2  * gnc-timezone.cpp - Retrieve timezone information from OS. *
3  * Copyright 2014 John Ralls <jralls@ceridwen.us> *
4  * Based on work done with Arnel Borja for GLib's gtimezone in 2012.*
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21 \********************************************************************/
22 
23 #ifndef __GNC_TIMEZONE_HPP__
24 #define __GNC_TIMEZONE_HPP__
25 extern "C"
26 {
27 #include <platform.h>
28 #if PLATFORM(WINDOWS)
29 #include <windows.h>
30 #endif
31 }
32 
33 #define BOOST_ERROR_CODE_HEADER_ONLY
34 #include <boost/date_time/local_time/local_time.hpp>
35 
36 namespace gnc
37 {
38  namespace date
39  {}
40 }// Move these later
41 using TZ = boost::local_time::time_zone;
42 using TZ_Ptr = boost::local_time::time_zone_ptr;
43 using TZ_Entry = std::pair<int, TZ_Ptr>;
44 using TZ_Vector = std::vector<TZ_Entry>;
45 using time_zone_names = boost::local_time::time_zone_names;
46 
48 {
49 public:
50  // The default constructor provides the time zone for the current locale
51  TimeZoneProvider() : TimeZoneProvider (static_cast<std::string>("")) {}
52  TimeZoneProvider(const std::string& tzname); //create a provider for a specified TZ.
53  TimeZoneProvider(const TimeZoneProvider&) = delete;
54  TimeZoneProvider(const TimeZoneProvider&&) = delete;
55  TimeZoneProvider operator=(const TimeZoneProvider&) = delete;
56  TimeZoneProvider operator=(const TimeZoneProvider&&) = delete;
57  TZ_Ptr get (int year) const noexcept;
58  void dump() const noexcept;
59  static const unsigned int min_year; //1400
60  static const unsigned int max_year; //9999
61 private:
62  void parse_file(const std::string& tzname);
63  bool construct(const std::string& tzname);
64  TZ_Vector m_zone_vector;
65 #if PLATFORM(WINDOWS)
66  void load_windows_dynamic_tz(HKEY, time_zone_names);
67  void load_windows_classic_tz(HKEY, time_zone_names);
68  void load_windows_default_tz(void);
69 #endif
70 };
71 
72 #endif //__GCN_TIMEZONE_HPP__