some minor attempt at fixing posix rules
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 9 Jul 2010 10:43:13 +0000 (10:43 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 9 Jul 2010 10:43:13 +0000 (10:43 +0000)
added posix rule scanner

git-svn-id: https://silmor.de/svn/softmagic/tzone/trunk@548 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

pscan/pscan.cpp [new file with mode: 0644]
pscan/pscan.pro [new file with mode: 0644]
tzfile.cpp
tzfile.h

diff --git a/pscan/pscan.cpp b/pscan/pscan.cpp
new file mode 100644 (file)
index 0000000..bcf6eec
--- /dev/null
@@ -0,0 +1,70 @@
+// This is a very simple POSIX Rule Scanner
+// I used it to find the possible variations in the fallback POSIX rules of the TZ DB
+
+#include <QtCore>
+#include "../tzfile.h"
+
+bool verbose=false;
+
+void scanFile(QString fn)
+{
+       using namespace TimeZoneLib;
+       QFile fd(fn);
+       if(!fd.open(QIODevice::ReadOnly)){
+               if(verbose)
+                       qDebug()<<"file unreadable"<<fn;
+               return;
+       }
+       TZFile tz(fd.readAll());
+       fd.close();
+       if(tz.isValid()){
+               if(verbose)
+                       qDebug()<<"file"<<fn<<":"<<tz.posixRule().asString();
+               else
+                       qDebug()<<tz.posixRule().asString();
+       }else
+               if(verbose)
+                       qDebug()<<"invalid file"<<fn;
+}
+
+void scanDir(QString d)
+{
+       QDir dir(d);
+       if(!dir.exists())return;
+       if(verbose)
+               qDebug()<<"entering dir"<<d;
+       QStringList de=dir.entryList();
+       for(int i=0;i<de.size();i++){
+               if(de[i]=="." || de[i]=="..")continue;
+               QString fn=d+"/"+de[i];
+               QFileInfo fi(fn);
+               if(fi.isFile()){
+                       if(fi.isReadable())
+                               scanFile(fn);
+                       else
+                               if(verbose)
+                                       qDebug()<<"skipping unreadable"<<fn;
+               }else
+               if(fi.isDir())
+                       scanDir(fn);
+               else
+                       if(verbose)
+                               qDebug()<<"skipping special"<<fn;
+       }
+}
+
+int main(int argc,char**argv)
+{
+       QCoreApplication app(argc,argv);
+       QStringList dl=app.arguments().mid(1);
+       if(dl.size()==0){
+               qDebug()<<"Usage: pscan [-v] directory ...";
+               return 1;
+       }
+       if(dl[0]=="-v"){
+               verbose=true;
+               dl=dl.mid(1);
+       }
+       for(int i=0;i<dl.size();i++)
+               scanDir(dl[i]);
+}
\ No newline at end of file
diff --git a/pscan/pscan.pro b/pscan/pscan.pro
new file mode 100644 (file)
index 0000000..9279c5b
--- /dev/null
@@ -0,0 +1,10 @@
+# This is a very simple POSIX Rule Scanner
+# I used it to find the possible variations in the fallback POSIX rules of the TZ DB
+
+TEMPLATE = app
+TARGET = pscan
+
+QT -= gui
+
+SOURCES += pscan.cpp ../tzfile.cpp
+HEADERS += ../tzfile.h
\ No newline at end of file
index e51cc98..99845af 100644 (file)
@@ -537,7 +537,7 @@ PosixRule::PosixRule(QString s)
 }
 
 //helper for rulesForYear: calculates the exact time of a transition
-static inline qint64 calcTimeStamp(int year,PosixRule::StartType type,int month,int week,int day,int time)
+static inline qint64 calcTimeStamp(int year,PosixRule::StartType type,int month,int week,int day,int time,int offset)
 {
        qint64 ret=0;
        switch(type){
@@ -558,7 +558,7 @@ static inline qint64 calcTimeStamp(int year,PosixRule::StartType type,int month,
                        break;
                default:return 0;
        }
-       return ret*SecondsPerDay+time;
+       return ret*SecondsPerDay+time-offset;
 }
 
 QList< TZRule > PosixRule::rulesForYear(int year) const
@@ -579,27 +579,27 @@ QList< TZRule > PosixRule::rulesForYear(int year) const
        start.m_abbr=m_abbrdst;
        start.m_off=m_offdst;
        start.m_isdst=true;
-       start.m_start=calcTimeStamp(year,m_types,m_months,m_weeks,m_days,m_times+m_off);
+       start.m_start=calcTimeStamp(year,m_types,m_months,m_weeks,m_days,m_times,m_off);
        
        //calculate end
        end.m_abbr=m_abbr;
        end.m_off=m_off;
        end.m_isdst=false;
-       end.m_start=calcTimeStamp(year,m_typee,m_monthe,m_weeke,m_daye,m_timee+m_offdst);
+       end.m_start=calcTimeStamp(year,m_typee,m_monthe,m_weeke,m_daye,m_timee,m_offdst);
        
        //calculate end of rules
        if(end<start){
                end.m_end=start.m_start;
-               start.m_end=calcTimeStamp(year+1,m_typee,m_monthe,m_weeke,m_daye,m_timee+m_offdst);
+               start.m_end=calcTimeStamp(year+1,m_typee,m_monthe,m_weeke,m_daye,m_timee,m_offdst);
                prev=end;
                prev.m_end=end.m_start;
-               prev.m_start=calcTimeStamp(year-1,m_types,m_months,m_weeks,m_days,m_times+m_off);
+               prev.m_start=calcTimeStamp(year-1,m_types,m_months,m_weeks,m_days,m_times,m_off);
        }else{
                start.m_end=end.m_start;
-               end.m_end=calcTimeStamp(year+1,m_types,m_months,m_weeks,m_days,m_times+m_off);
+               end.m_end=calcTimeStamp(year+1,m_types,m_months,m_weeks,m_days,m_times,m_off);
                prev=start;
                prev.m_end=start.m_start;
-               prev.m_start=calcTimeStamp(year-1,m_typee,m_monthe,m_weeke,m_daye,m_timee+m_offdst);
+               prev.m_start=calcTimeStamp(year-1,m_typee,m_monthe,m_weeke,m_daye,m_timee,m_offdst);
        }
        
        QList<TZRule>ret;
@@ -622,8 +622,15 @@ TZRule PosixRule::ruleForTime(qint64 ) const
        return TZRule();
 }
 
-TZRule PosixRule::ruleForLocalTime ( qint64 ) const
+TZRule PosixRule::ruleForLocalTime ( qint64 ts) const
 {
+       //calculate local time - we need the year
+       qint16 y;
+       quint8 mo,d,h,mi,s;
+       stamp2Date(ts,y,mo,d);
+       stamp2Time(ts,h,mi,s);
+       //is it standard or DST?
+       
 #warning not implemented
        //TODO!!!
        return TZRule();
index 29f7b11..fb46528 100644 (file)
--- a/tzfile.h
+++ b/tzfile.h
@@ -168,6 +168,15 @@ class TZFile
                /**returns a rule that matches a specific local time, the timestamp given is a Unix timestamp plus the offset of the rule that will match; in other words it was calculated assuming UTC and now looks for a rule that will provide a correcting offset*/
                TZRule ruleForLocalTime(qint64);
                
+               /**returns the list of rules that were encoded in the file*/
+               QList<TZRule> fileRules()const{return m_file;}
+               
+               /**returns the fallback POSIX rule that was encoded in the file (or an invalid rule if there was none)*/
+               PosixRule posixRule()const{return m_posix;}
+               
+               /**returns all currently cached rules that were auto-generated during the lifetime of this file object*/
+               QList<TZRule> cachedRules()const{return m_cache;}
+               
                /**returns the search paths for time zone files*/
                static QStringList searchPath();
                /**sets new search paths for time zone files*/