Package: doxygen Version: 1.8.9.1-3 Followup-For: Bug #785624 Tags: patch User: reproducible-bui...@lists.alioth.debian.org Usertags: timestamps
Hi. I created a patch for doxygen that allow get the current date and time from the DOXYGEN_CURRENTDATETIME environment variable in iso 8601 extended format. The expected usage in the debian/rules file is the following: LAST_CHANGE = $(shell dpkg-parsechangelog -S Date) DOXYGEN_CURRENTDATETIME = $(shell LC_ALL=C date -uIs -d "$(LAST_CHANGE)") export DOXYGEN_CURRENTDATETIME Comments are welcome. Greetings, Juan Picca Note: the code for parse the date is simplified from QDateTime
Description: Allow set doxygen current date time from environment variable Allow use the DOXYGEN_CURRENTDATETIME environment variable for modify the current date and time used by doxygen for timestamp values. The expected format for DOXYGEN_CURRENTDATETIME is the ISO 8601 extended format. The code for parse the text in iso 8601 format is a simplification of the code from QDateTime::fromString, QDate::fromString and QTime::fromString. Author: Juan Picca <jumap...@gmail.com> Last-Update: 2015-06-29 --- --- a/src/rtfgen.cpp +++ b/src/rtfgen.cpp @@ -49,7 +49,7 @@ static QCString dateToRTFDateString() { - const QDateTime &d = QDateTime::currentDateTime(); + const QDateTime &d = DoxygenDateTime::get(); QCString result; result.sprintf("\\yr%d\\mo%d\\dy%d\\hr%d\\min%d\\sec%d", d.date().year(), d.date().month(), d.date().day(), --- a/src/util.cpp +++ b/src/util.cpp @@ -90,6 +90,95 @@ #define REL_PATH_TO_ROOT "../../" //------------------------------------------------------------------------ +// DoxygenDateTime implementation +//------------------------------------------------------------------------ + +QDateTime DoxygenDateTime::current; // initialize static to null + +QDateTime DoxygenDateTime::get() +{ + if (current.isNull()) + { + if (const char* env_p = std::getenv("DOXYGEN_CURRENTDATETIME")) + { + current = parseIso8601(env_p); + } + if (!current.isValid()) + { + current = QDateTime::currentDateTime(); + } + } + return current; +} + +QDateTime DoxygenDateTime::parseIso8601(const QString& s) +{ + if (s.isEmpty()) + { + return QDateTime(); + } + QString tmp = s; + const QDate date = parseIso8601Date(tmp.left(10)); + if (tmp.length() == 10) + { + return QDateTime(date); + } + tmp = tmp.mid(11); + if (tmp.at(tmp.length() - 1) == 'Z') + { + // skip UTC specifications + tmp = tmp.left(tmp.length() - 1); + } + else + { + // skip timezone specifications + QRegExp rx(QString("[+-]").latin1()); + if (tmp.contains(rx)) + { + int idx = tmp.find(rx); + tmp = tmp.left(idx); + } + } + const QTime time = parseIso8601Time(tmp); + return QDateTime(date, time); +} + +QDate DoxygenDateTime::parseIso8601Date(const QString& s) +{ + if (s.isEmpty()) + { + return QDate(); + } + int year(s.mid(0, 4).toInt()); + int month(s.mid(5, 2).toInt()); + int day(s.mid(8, 2).toInt()); + if (year && month && day) { + return QDate(year, month, day); + } + return QDate(); +} + +QTime DoxygenDateTime::parseIso8601Time(const QString& s) +{ + if (s.isEmpty()) + { + return QTime(); + } + bool ok = true; + const int hour(s.mid(0, 2).toInt(&ok)); + if (!ok) + return QTime(); + const int minute(s.mid(3, 2).toInt(&ok)); + if (!ok) + return QTime(); + const int second(s.mid(6, 2).toInt(&ok)); + if (!ok) + return QTime(); + // ignore msec if exists + return QTime(hour, minute, second, 0); +} + +//------------------------------------------------------------------------ // TextGeneratorOLImpl implementation //------------------------------------------------------------------------ @@ -2460,7 +2549,7 @@ QCString fileToString(const char *name,b QCString dateToString(bool includeTime) { - QDateTime current = QDateTime::currentDateTime(); + QDateTime current = DoxygenDateTime::get(); return theTranslator->trDateTime(current.date().year(), current.date().month(), current.date().day(), @@ -2473,7 +2562,7 @@ QCString dateToString(bool includeTime) QCString yearToString() { - const QDate &d=QDate::currentDate(); + const QDate &d = DoxygenDateTime::get().date(); QCString result; result.sprintf("%d", d.year()); return result; --- a/src/util.h +++ b/src/util.h @@ -24,6 +24,8 @@ #include <qlist.h> #include <ctype.h> +#include <cstdlib> +#include <qdatetime.h> #include "types.h" #include "sortdict.h" #include "docparser.h" @@ -60,6 +62,18 @@ class FTextStream; //-------------------------------------------------------------------- +/** Handle the doxygen date and time. */ +class DoxygenDateTime +{ + public: + static QDateTime get(); + private: + static QDateTime current; + static QDateTime parseIso8601(const QString& s); + static QDate parseIso8601Date(const QString& s); + static QTime parseIso8601Time(const QString& s); +}; + /** Abstract interface for a hyperlinked text fragment. */ class TextGeneratorIntf {