--- /dev/null
+// 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
}
//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){
break;
default:return 0;
}
- return ret*SecondsPerDay+time;
+ return ret*SecondsPerDay+time-offset;
}
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;
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();
/**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*/