mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#3428 Text string creation based on date and time : Add helper function
This commit is contained in:
parent
bd79bd89c1
commit
a083e70ea1
@ -18,8 +18,9 @@
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
#include <cvfAssert.h>
|
||||
|
||||
@ -357,3 +358,18 @@ QString RiaQDateTimeTools::dateTimePeriodName(DateTimePeriod period)
|
||||
default: return "None";
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaQDateTimeTools::toStringUsingApplicationLocale(const QDateTime& dt, const QString& format)
|
||||
{
|
||||
// Default application locale is set in RiaMain
|
||||
// QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
//
|
||||
// QDate/QDateTime use system locale for toString() functions
|
||||
|
||||
QLocale defaultApplicationLocale;
|
||||
|
||||
return defaultApplicationLocale.toString(dt, format);
|
||||
}
|
||||
|
@ -101,6 +101,10 @@ public:
|
||||
static std::vector<DateTimePeriod> dateTimePeriods();
|
||||
static QString dateTimePeriodName(DateTimePeriod period);
|
||||
|
||||
// This function uses C locale to make sure the text representation of a date is stable, independent of the locale
|
||||
// settings on local machine. Required for stable regression testing.
|
||||
static QString toStringUsingApplicationLocale(const QDateTime& dt, const QString& format);
|
||||
|
||||
private:
|
||||
static quint64 secondsInDay();
|
||||
static quint64 secondsInYear();
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
#include "RiaTestDataDirectory.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafFilePath.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
@ -71,3 +73,28 @@ TEST(RimRelocatePathTest, findPathsInProjectFile)
|
||||
std::cout << filePath->path().toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RimRelocatePathTest, DISABLED_LocaleDateStringTest)
|
||||
{
|
||||
// Set a non-english system locale on local machine for this test to be useful
|
||||
|
||||
QDateTime dt;
|
||||
{
|
||||
QDate d(2018, 10, 1);
|
||||
dt.setDate(d);
|
||||
}
|
||||
|
||||
QString formatString("ddd MMM yyyy");
|
||||
|
||||
// Change the default locale on your system to get a different text then the english formatted text
|
||||
QString defaultString = dt.toString(formatString);
|
||||
|
||||
std::cout << "default " << defaultString.toStdString() << std::endl;
|
||||
|
||||
QString englishString = RiaQDateTimeTools::toStringUsingApplicationLocale(dt, formatString);
|
||||
|
||||
std::cout << "english " << englishString.toStdString() << std::endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user