File: zoneconvert.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (28 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (3)
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
#include "datetime.ih"

    // dst specification:   Mon, wkspec Day [hh:mm]
    // wkspec: 1st, 2nd, 3rd, 4th, 5th, or last

// static
string DateTime::Zone::convert(string const &dstSpec)
{
    vector<string> vs;
    String::split(&vs, dstSpec, String::TOK, ", "); // get the , and space
                                                    // separated elements

    if (vs.size() < 3 || vs.size() > 4)
        throw 1;

    string monthNr = to_string(1 + stdFind(s_month, 12, vs[0]));

    char wkSpec =                                       // handle 1st, etc.
            "1234"s.find(vs[1][0]) != string::npos ?    // Otherwise: '5'
                vs[1][0]                                // for last
            :
                '5';

    char dayOffset = '0' + stdFind(s_day, 7, vs[2]);

    return ",M"s + monthNr + '.' + wkSpec + '.' + dayOffset +
            (vs.size() == 4 ? '/' + vs.back() : "");
}