| 1 | // |
|---|---|
| 2 | // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | #ifndef BOOST_LOCALE_IMPL_UTIL_TIMEZONE_HPP |
| 8 | #define BOOST_LOCALE_IMPL_UTIL_TIMEZONE_HPP |
| 9 | #include <boost/locale/util/string.hpp> |
| 10 | #include <cstdlib> |
| 11 | #include <cstring> |
| 12 | #include <string> |
| 13 | |
| 14 | namespace boost { namespace locale { namespace util { |
| 15 | inline int parse_tz(const std::string& tz) |
| 16 | { |
| 17 | std::string ltz; |
| 18 | for(const char c : tz) { |
| 19 | if(is_lower_ascii(c)) |
| 20 | ltz += c - 'a' + 'A'; |
| 21 | else if(c != ' ') |
| 22 | ltz += c; |
| 23 | } |
| 24 | if(ltz.compare(pos: 0, n1: 3, s: "GMT") != 0 && ltz.compare(pos: 0, n1: 3, s: "UTC") != 0) |
| 25 | return 0; |
| 26 | if(ltz.size() <= 3) |
| 27 | return 0; |
| 28 | int gmtoff = 0; |
| 29 | const char* begin = ltz.c_str() + 3; |
| 30 | char* end = const_cast<char*>(begin); |
| 31 | int hours = strtol(nptr: begin, endptr: &end, base: 10); |
| 32 | if(end != begin) |
| 33 | gmtoff += hours * 3600; |
| 34 | if(*end == ':') { |
| 35 | begin = end + 1; |
| 36 | int minutes = strtol(nptr: begin, endptr: &end, base: 10); |
| 37 | if(end != begin) |
| 38 | gmtoff += minutes * 60; |
| 39 | } |
| 40 | return gmtoff; |
| 41 | } |
| 42 | |
| 43 | }}} // namespace boost::locale::util |
| 44 | |
| 45 | #endif |
| 46 |
