mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Fixed a time zone issue related to the Unix epoch.
This commit is contained in:
parent
a88a6dcd78
commit
a4f8fe78e1
|
@ -25,7 +25,7 @@ namespace
|
|||
{"sortname", MD_STRING, "", false, "sortname", "enter sortname", false},
|
||||
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true},
|
||||
{"rating", MD_RATING, "0", false, "rating", "enter rating", true},
|
||||
{"releasedate", MD_DATE, "19700101T010000", false, "release date", "enter release date", true},
|
||||
{"releasedate", MD_DATE, "19700101T000000", false, "release date", "enter release date", true},
|
||||
{"developer", MD_STRING, "unknown", false, "developer", "enter developer", true},
|
||||
{"publisher", MD_STRING, "unknown", false, "publisher", "enter publisher", true},
|
||||
{"genre", MD_STRING, "unknown", false, "genre", "enter genre", true},
|
||||
|
@ -48,7 +48,7 @@ namespace
|
|||
{"name", MD_STRING, "", false, "name", "enter name", true},
|
||||
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true},
|
||||
{"rating", MD_RATING, "0", false, "rating", "enter rating", true},
|
||||
{"releasedate", MD_DATE, "19700101T010000", false, "release date", "enter release date", true},
|
||||
{"releasedate", MD_DATE, "19700101T000000", false, "release date", "enter release date", true},
|
||||
{"developer", MD_STRING, "unknown", false, "developer", "enter developer", true},
|
||||
{"publisher", MD_STRING, "unknown", false, "publisher", "enter publisher", true},
|
||||
{"genre", MD_STRING, "unknown", false, "genre", "enter genre", true},
|
||||
|
|
|
@ -532,7 +532,7 @@ void GuiScraperSearch::updateInfoPane()
|
|||
}
|
||||
// Set the release date to this value to force DateTimeEditComponent to put a
|
||||
// blank instead of the text 'unknown' prior to the scrape result being returned.
|
||||
mMD_ReleaseDate->setValue("19700101T010101");
|
||||
mMD_ReleaseDate->setValue("19710101T010101");
|
||||
mMD_Developer->setText("");
|
||||
mMD_Publisher->setText("");
|
||||
mMD_Genre->setText("");
|
||||
|
@ -906,7 +906,7 @@ bool GuiScraperSearch::saveMetadata(const ScraperSearchResult& result,
|
|||
continue;
|
||||
|
||||
// Make sure to set releasedate to the proper default value.
|
||||
if (key == "releasedate" && metadata.get(key) == "19700101T010000")
|
||||
if (key == "releasedate" && metadata.get(key) == "19700101T000000")
|
||||
metadata.set(key, mMetaDataDecl.at(i).defaultValue);
|
||||
|
||||
// Overwrite all the other values if the flag to overwrite data has been set.
|
||||
|
|
|
@ -70,8 +70,8 @@ void DateTimeComponent::onTextChanged()
|
|||
std::string DateTimeComponent::getDisplayString() const
|
||||
{
|
||||
if (mDisplayRelative) {
|
||||
// Relative time.
|
||||
if (mTime.getTime() == 0)
|
||||
// Workaround to handle Unix epoch for different time zones.
|
||||
if (mTime.getTime() < 82800)
|
||||
return "never";
|
||||
|
||||
Utils::Time::DateTime now(Utils::Time::now());
|
||||
|
|
|
@ -63,9 +63,9 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
|
|||
// Started editing.
|
||||
mTimeBeforeEdit = mTime;
|
||||
|
||||
// Initialize to now if unset.
|
||||
if (mTime.getTime() == Utils::Time::DEFAULT_TIMEVALUE) {
|
||||
mTime = Utils::Time::stringToTime("19990101T0101");
|
||||
// Initialize to the arbitrary value 1999-01-01 if unset.
|
||||
if (mTime == 0) {
|
||||
mTime = Utils::Time::stringToTime("19990101T000000");
|
||||
updateTextCache();
|
||||
}
|
||||
}
|
||||
|
@ -307,6 +307,13 @@ void DateTimeEditComponent::changeDate()
|
|||
{
|
||||
tm new_tm = mTime;
|
||||
|
||||
if (mTime.getIsoString() == "19700101T000000")
|
||||
#if defined(_WIN64)
|
||||
new_tm = {0, 0, 0, 1, 0, 70, 0, 0, -1};
|
||||
#else
|
||||
new_tm = {0, 0, 0, 1, 0, 70, 0, 0, -1, 0, 0};
|
||||
#endif
|
||||
|
||||
// ISO 8601 date format.
|
||||
if (mEditIndex == 0) {
|
||||
new_tm.tm_year += mKeyRepeatDir;
|
||||
|
@ -338,7 +345,10 @@ void DateTimeEditComponent::changeDate()
|
|||
if (new_tm.tm_mday > days_in_month)
|
||||
new_tm.tm_mday = days_in_month;
|
||||
|
||||
mTime = new_tm;
|
||||
if (mktime(&new_tm) <= 0)
|
||||
mTime = 0;
|
||||
else
|
||||
mTime = new_tm;
|
||||
|
||||
updateTextCache();
|
||||
}
|
||||
|
@ -351,7 +361,7 @@ void DateTimeEditComponent::updateTextCache()
|
|||
|
||||
// Hack to set date string to blank instead of 'unknown'.
|
||||
// The calling function simply needs to set this string using setValue().
|
||||
if (mTime.getIsoString() == "19700101T010101") {
|
||||
if (mTime.getIsoString() == "19710101T010101") {
|
||||
dispString = "";
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include "utils/TimeUtil.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
namespace Time
|
||||
|
@ -23,7 +21,7 @@ namespace Utils
|
|||
#else
|
||||
mTimeStruct = {0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0};
|
||||
#endif
|
||||
mIsoString = "00000000T000000";
|
||||
mIsoString = "19000101T000000";
|
||||
}
|
||||
|
||||
DateTime::DateTime(const time_t& time)
|
||||
|
@ -46,7 +44,12 @@ namespace Utils
|
|||
|
||||
void DateTime::setTime(const time_t& time)
|
||||
{
|
||||
mTime = (time < 0) ? 0 : time;
|
||||
// Workaround to handle Unix epoch for different time zones.
|
||||
if (time < 82800)
|
||||
mTime = 0;
|
||||
else
|
||||
mTime = time;
|
||||
|
||||
#if defined(_WIN64)
|
||||
localtime_s(&mTimeStruct, &mTime);
|
||||
#else
|
||||
|
@ -94,8 +97,8 @@ namespace Utils
|
|||
#endif
|
||||
size_t parsedChars = 0;
|
||||
|
||||
if (string == "19700101T010000")
|
||||
return mktime(&timeStruct);
|
||||
if (string == "19700101T000000")
|
||||
return 0;
|
||||
|
||||
while (*f && (parsedChars < string.length())) {
|
||||
if (*f == '%') {
|
||||
|
@ -173,6 +176,10 @@ namespace Utils
|
|||
|
||||
std::string timeToString(const time_t& time, const std::string& format)
|
||||
{
|
||||
// Workaround to handle Unix epoch for different time zones.
|
||||
if (time < 82800)
|
||||
return "19700101T000000";
|
||||
|
||||
const char* f = format.c_str();
|
||||
tm timeStruct;
|
||||
#if defined(_WIN64)
|
||||
|
|
|
@ -10,18 +10,13 @@
|
|||
#ifndef ES_CORE_UTILS_TIME_UTIL_H
|
||||
#define ES_CORE_UTILS_TIME_UTIL_H
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
#include <ctime>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
namespace Time
|
||||
{
|
||||
constexpr static int DEFAULT_TIMEVALUE = 0;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue