aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx
blob: 9bdb7e46a4d8275f379adcca9f0599d3bac98619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// file      : xsde/cxx/parser/non-validating/time-zone.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <xsde/cxx/parser/non-validating/time-zone.hxx>

namespace xsde
{
  namespace cxx
  {
    namespace parser
    {
      namespace non_validating
      {
        namespace bits
        {
          void
          parse_time_zone (const char* s, size_t n, short& h, short& m)
          {
            // time_zone := Z|(+|-)HH:MM
            //
            if (n == 0)
            {
              return;
            }
            else if (s[0] == 'Z')
            {
              h = 0;
              m = 0;
            }
            else if (n == 6)
            {
              // Parse hours.
              //
              h = 10 * (s[1] - '0') + (s[2] - '0');

              // Parse minutes.
              //
              m = 10 * (s[4] - '0') + (s[5] - '0');

              if (s[0] == '-')
              {
                h = -h;
                m = -m;
              }
            }
          }
        }
      }
    }
  }
}