fix some compiler warnings; refactor TZDB update for easier GIT diff
authorKonrad Rosenbaum <konrad@silmor.de>
Sat, 25 Apr 2020 10:39:39 +0000 (12:39 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Sat, 25 Apr 2020 10:39:39 +0000 (12:39 +0200)
src/tzfile.cpp
src/tzhelp.h
update-timedb.sh [moved from db/update.sh with 97% similarity]

index 904188d..5a51643 100644 (file)
@@ -39,6 +39,15 @@ using namespace TimeZoneLib;
   NoDebug& operator<<(bool){return*this;}
  };
 #endif
+//qSort is deprecated, long live lSort
+#include <algorithm>
+template<class Cont>
+static inline void lSort(Cont &c)
+{
+    std::sort(c.begin(),c.end());
+}
 
 
 /* **************************************************************
@@ -284,7 +293,7 @@ int TZFile::load(const QByteArray& a,char tversion)
        m_posix=PosixRule(posix);
        
        //sort and add end times
-       qSort(m_file);
+       lSort(m_file);
        for(int i=0;i<(m_file.size()-1);i++)
                m_file[i].setEnd(m_file[i+1].startTime());
        if(m_file.size())
@@ -712,7 +721,7 @@ QList< TZRule > PosixRule::rulesForYear(int year) const
        else ret<<end;
        
        //calculate end of rules
-       qSort(ret);
+       lSort(ret);
        for(int i=1;i<ret.size();i++)
                ret[i-1].m_end=ret[i].m_start;
        //truncate last rule, we do not need it
@@ -734,7 +743,7 @@ TZRule PosixRule::nextRule(const TZRule& r) const
        rl<<createRule(y+1,true)<<createRule(y+1,false);
        rl<<createRule(y+2,true)<<createRule(y+2,false);
        //sort and extend
-       qSort(rl);
+       lSort(rl);
        for(int i=1;i<rl.size();i++)
                rl[i-1].m_end=rl[i].m_start;
        //find the first one that is later and on a different offset
index 8e1909f..7369f20 100644 (file)
 #include <QtGlobal>
 #include <QByteArray>
 
+#ifndef Q_FALLTHROUGH
+//introduced in Qt 5.14, for backward compat:
+#define Q_FALLTHROUGH()
+#endif
+
 namespace TimeZoneLib {
 
 /**the amount of seconds per Day*/
@@ -69,17 +74,17 @@ inline qint64 daysSinceEpoch(int year,int month=1,int day=1)
        //calculate 1st of month
        // for each month: add the days of the previous one, and the previous, ...
        switch(month){
-               case 12:ret+=30;//nov
-               case 11:ret+=31;//oct
-               case 10:ret+=30;//sep
-               case 9:ret+=31;//aug
-               case 8:ret+=31;//jul
-               case 7:ret+=30;//jun
-               case 6:ret+=31;//may
-               case 5:ret+=30;//apr
-               case 4:ret+=31;//mar
-               case 3:ret+=28;if(isLeapYear(year))ret++;//feb
-               case 2:ret+=31;//jan
+               case 12:ret+=30;Q_FALLTHROUGH(); //nov
+        case 11:ret+=31;Q_FALLTHROUGH(); //oct
+        case 10:ret+=30;Q_FALLTHROUGH(); //sep
+        case 9:ret+=31;Q_FALLTHROUGH(); //aug
+        case 8:ret+=31;Q_FALLTHROUGH(); //jul
+        case 7:ret+=30;Q_FALLTHROUGH(); //jun
+        case 6:ret+=31;Q_FALLTHROUGH(); //may
+        case 5:ret+=30;Q_FALLTHROUGH(); //apr
+        case 4:ret+=31;Q_FALLTHROUGH(); //mar
+        case 3:ret+=28;if(isLeapYear(year))ret++;Q_FALLTHROUGH(); //feb
+        case 2:ret+=31;Q_FALLTHROUGH(); //jan
                default:break;
        }
        //add day
similarity index 97%
rename from db/update.sh
rename to update-timedb.sh
index b49a7bb..d81dc20 100755 (executable)
@@ -3,9 +3,10 @@
 set -e
 
 cd `dirname $0`
+cd db
 
 echo Cleaning up.
-rm -f tzdata* tzcode*
+rm -f *