-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimezoneparseposix.cpp
67 lines (57 loc) · 1.31 KB
/
timezoneparseposix.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "timezoneparseposix.h"
TimeZoneParsePosix::TimeZoneParsePosix(QString data)
{
if (data.isEmpty() || data.isNull())
throw "Empty data.";
this->data = data;
init();
}
void TimeZoneParsePosix::init()
{
loadZones();
setTZ();
}
void TimeZoneParsePosix::loadZones()
{
QFile mFile(":/TimeZone/timezonesdb.csv");
if( !mFile.open(QFile::ReadOnly | QFile::Text) ){
qDebug() << "could not open file for read";
return;
}
QTextStream in(&mFile);
QStringList z = in.readAll().split("\n");
mFile.close();
QList<QStringList> mzones;
foreach (QString ms, z) {
int c = ms.split(",").count() ;
if (c > 3) {
mzones.append(ms.replace("\"","").split(","));
} else if (c == 3){
QStringList l;
QStringList s = ms.replace("\"","").split(",");
l << s.at(0) << s.at(1) << "" << "" << s.at(2);
mzones.append(l);
}
}
this->zones = mzones;
}
void TimeZoneParsePosix::setTZ()
{
QStringList tl = data.split(",");
int c = tl.count();
if (c == 1){
foreach (QStringList sl, zones) {
if ( sl.at(1).compare( tl.at(0)) == 0) {
TZ = sl.at(0);
break;
}
}
} else if ( c == 3 ){
foreach (QStringList sl, zones) {
if( sl.at(1).contains(tl.at(0)) && sl.at(2).contains(tl.at(1).split("/").first()) && sl.at(3).contains(tl.at(2).split("/").first()) ){
TZ = sl.at(0);
break;
}
}
}
}