Created
August 17, 2025 15:21
-
-
Save amlel-el-mahrouss/fcffbffa267a2e418706876b9d71e0be to your computer and use it in GitHub Desktop.
A simple helper for date parsing using the Qt framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QDate> | |
#include <QDebug> | |
#include <iostream> | |
enum class debug_date : int32_t | |
{ | |
invalid, | |
yyyy_mm_dd, | |
}; | |
template <debug_date Fmt> | |
void debug_date_qt(const QDate &date) noexcept | |
{ | |
if (!date.isValid()) { | |
qDebug() << "QDate(\"null\")"; | |
return; | |
} | |
switch (Fmt) | |
{ | |
case debug_date::yyyy_mm_dd: { | |
qDebug() << date; | |
break; | |
} | |
default:{ | |
qDebug() << "QDate(\"undefined\")"; | |
break; | |
} | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QDate date(1994, 10, 21); | |
date = date.addYears(31); | |
// invalid cast | |
debug_date_qt<debug_date::invalid>(date); | |
// correct cast | |
debug_date_qt<debug_date::yyyy_mm_dd>(date); | |
// invalid cast | |
debug_date_qt<debug_date::yyyy_mm_dd>({}); | |
return a.exec(); | |
} |
Comments are disabled for this gist.