• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_LOCALE_IMPL_UTIL_TIMEZONE_HPP
9 #define BOOST_LOCALE_IMPL_UTIL_TIMEZONE_HPP
10 #include <string>
11 #include <stdlib.h>
12 #include <string.h>
13 namespace boost {
14 namespace locale {
15 namespace util {
parse_tz(std::string const & tz)16     inline int parse_tz(std::string const &tz)
17     {
18         int gmtoff = 0;
19         std::string ltz;
20         for(unsigned i=0;i<tz.size();i++) {
21             if('a' <= tz[i] && tz[i] <= 'z')
22                 ltz += tz[i]-'a' + 'A';
23             else if(tz[i]==' ')
24                 ;
25             else
26                 ltz+=tz[i];
27         }
28         if(ltz.compare(0,3,"GMT")!=0 && ltz.compare(0,3,"UTC")!=0)
29             return 0;
30         if(ltz.size()<=3)
31             return 0;
32         char const *begin = ltz.c_str()+3;
33         char *end=0;
34         int hours = strtol(begin,&end,10);
35         if(end != begin) {
36             gmtoff+=hours * 3600;
37         }
38         if(*end==':') {
39             begin=end+1;
40             int minutes = strtol(begin,&end,10);
41             if(end!=begin)
42                 gmtoff+=minutes * 60;
43         }
44         return gmtoff;
45     }
46 
47 } // util
48 } // locale
49 } //boost
50 
51 
52 #endif
53 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
54