#3274: Fix localtime_r for VxWorks 6.9 and later

This commit is contained in:
Günter Obiltschnig 2021-06-15 15:14:11 +02:00
parent d4ec18d503
commit 19b2c5b415
2 changed files with 16 additions and 12 deletions

View File

@ -99,7 +99,7 @@ LocalDateTime::LocalDateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff
adjustForTzd();
}
LocalDateTime::~LocalDateTime()
{
}
@ -179,31 +179,31 @@ bool LocalDateTime::operator == (const LocalDateTime& dateTime) const
}
bool LocalDateTime::operator != (const LocalDateTime& dateTime) const
bool LocalDateTime::operator != (const LocalDateTime& dateTime) const
{
return utcTime() != dateTime.utcTime();
}
bool LocalDateTime::operator < (const LocalDateTime& dateTime) const
bool LocalDateTime::operator < (const LocalDateTime& dateTime) const
{
return utcTime() < dateTime.utcTime();
}
bool LocalDateTime::operator <= (const LocalDateTime& dateTime) const
bool LocalDateTime::operator <= (const LocalDateTime& dateTime) const
{
return utcTime() <= dateTime.utcTime();
}
bool LocalDateTime::operator > (const LocalDateTime& dateTime) const
bool LocalDateTime::operator > (const LocalDateTime& dateTime) const
{
return utcTime() > dateTime.utcTime();
}
bool LocalDateTime::operator >= (const LocalDateTime& dateTime) const
bool LocalDateTime::operator >= (const LocalDateTime& dateTime) const
{
return utcTime() >= dateTime.utcTime();
}
@ -270,7 +270,7 @@ void LocalDateTime::determineTzd(bool adjust)
_tzd = (Timezone::utcOffset() + ((broken->tm_isdst == 1) ? 3600 : 0));
#else
std::tm broken;
#if defined(POCO_VXWORKS)
#if defined(POCO_VXWORKS) && (defined(_VXWORKS_COMPATIBILITY_MODE) || (defined(_WRS_VXWORKS_MAJOR) && ((_WRS_VXWORKS_MAJOR < 6) || ((_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR < 9)))))
if (localtime_r(&epochTime, &broken) != OK)
throw Poco::SystemException("cannot get local time");
#else
@ -307,7 +307,7 @@ std::time_t LocalDateTime::dstOffset(int& dstOffset) const
#else
local = std::mktime(&broken);
#endif
dstOffset = (broken.tm_isdst == 1) ? 3600 : 0;
return local;
}

View File

@ -30,12 +30,16 @@ int Timezone::utcOffset()
return now - utc;
}
int Timezone::dst()
{
std::time_t now = std::time(NULL);
struct std::tm t;
#if defined(_VXWORKS_COMPATIBILITY_MODE) || (defined(_WRS_VXWORKS_MAJOR) && ((_WRS_VXWORKS_MAJOR < 6) || ((_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR < 9))))
if (localtime_r(&now, &t) != OK)
#else
if (!localtime_r(&now, &t))
#endif
throw Poco::SystemException("cannot get local time DST offset");
return t.tm_isdst == 1 ? 3600 : 0;
}
@ -49,7 +53,7 @@ bool Timezone::isDst(const Timestamp& timestamp)
return tms->tm_isdst > 0;
}
std::string Timezone::name()
{
// format of TIMEZONE environment variable:
@ -62,13 +66,13 @@ std::string Timezone::name()
return tz;
}
std::string Timezone::standardName()
{
return name();
}
std::string Timezone::dstName()
{
return name();