Branch data Line data Source code
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 : :
26 : : #include <platform.h>
27 : : #if PLATFORM(WINDOWS)
28 : : #include <windows.h>
29 : : #endif
30 : :
31 : : #define BOOST_ERROR_CODE_HEADER_ONLY
32 : : #include <boost/date_time/local_time/local_time.hpp>
33 : :
34 : : namespace gnc
35 : : {
36 : : namespace date
37 : : {}
38 : : }// Move these later
39 : : using TZ = boost::local_time::time_zone;
40 : : using TZ_Ptr = boost::local_time::time_zone_ptr;
41 : : using TZ_Entry = std::pair<int, TZ_Ptr>;
42 : : using TZ_Vector = std::vector<TZ_Entry>;
43 : : using time_zone_names = boost::local_time::time_zone_names;
44 : :
45 : : class TimeZoneProvider
46 : : {
47 : : public:
48 : : // The default constructor provides the time zone for the current locale
49 : 342 : TimeZoneProvider() : TimeZoneProvider (static_cast<std::string>("")) {}
50 : : TimeZoneProvider(const std::string& tzname); //create a provider for a specified TZ.
51 : : TimeZoneProvider(const TimeZoneProvider&) = delete;
52 : : TimeZoneProvider(const TimeZoneProvider&&) = delete;
53 : : TimeZoneProvider operator=(const TimeZoneProvider&) = delete;
54 : : TimeZoneProvider operator=(const TimeZoneProvider&&) = delete;
55 : : TZ_Ptr get (int year) const noexcept;
56 : : void dump() const noexcept;
57 : : static const unsigned int min_year; //1400
58 : : static const unsigned int max_year; //9999
59 : : private:
60 : : void parse_file(const std::string& tzname);
61 : : bool construct(const std::string& tzname);
62 : : TZ_Vector m_zone_vector;
63 : : #if PLATFORM(WINDOWS)
64 : : void load_windows_dynamic_tz(HKEY, time_zone_names);
65 : : void load_windows_classic_tz(HKEY, time_zone_names);
66 : : void load_windows_default_tz(void);
67 : : #endif
68 : : };
69 : :
70 : : #endif //__GCN_TIMEZONE_HPP__
|