Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5428: No <ctime> function in Windows CE 6.0
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-01-30 17:45:43
#5428: No <ctime> function in Windows CE 6.0
--------------------------------------------------------+-------------------
Reporter: Akira Takahashi <faithandbrave@â¦> | Owner: az_sw_dude
Type: Bugs | Status: new
Milestone: To Be Determined | Component: date_time
Version: Boost 1.46.1 | Severity: Problem
Resolution: | Keywords: wince
--------------------------------------------------------+-------------------
Comment (by Ulrich Eckhardt <ulrich.eckhardt@â¦>):
The above implementation of localtime from sqlite is incorrect, AFAICT.
The problem is that the tm_yday and tm_isdst fields are not set correctly.
Further, even the hour differs sometimes, which I guess might be due to
the daylight saving time offsets. I haven't completely figured out how to
pull that info out of the system.
The code for gmtime() below was tested on a German MS Windows XP system
for time_t values between 1 and 0xfffffff8, using the native gmtime()
implementation of VC8 as reference. Both yield the same results. This also
runs on MS Windows CE6, though I still need to test a few checkpoint
values since I don't have a native gmtime() at my service there.
I'm a bit unsure if I can simply set the tm_isdst to zero for gmtime(),
maybe someone else could jump in here.
{{{
//! requires a pointer to a user created std::tm struct
inline
static std::tm* gmtime(const std::time_t* t, std::tm* result)
{
/* Three conversions here:
1. convert to 64-bit type to avoid overflows
2. epoch beginning 1970 to one beginning 1601
3. seconds to 100ns steps */
int64_t t64 = static_cast<int64_t>(*t);
t64 += 11644473600;
t64 *= 10000000;
// convert to FILETIME struct
FILETIME utc_time;
utc_time.dwLowDateTime = static_cast<DWORD>(t64 & 0xFFFFFFFF);
utc_time.dwHighDateTime= static_cast<DWORD>(t64 >> 32);
// split into year, month, day etc
SYSTEMTIME st;
if(!FileTimeToSystemTime(&utc_time, &st))
boost::throw_exception(std::runtime_error("could not convert
calendar time to local time"));
result->tm_year = st.wYear - 1900;
result->tm_mon = st.wMonth - 1;
result->tm_wday = st.wDayOfWeek;
result->tm_mday = st.wDay;
result->tm_hour = st.wHour;
result->tm_min = st.wMinute;
result->tm_sec = st.wSecond;
// compute day of year
bool leapyear;
if((st.wYear % 1000) == 0)
leapyear = true;
else if((st.wYear % 100) == 0)
leapyear = false;
else if((st.wYear % 4) == 0)
leapyear = true;
else
leapyear = false;
result->tm_yday = result->tm_mday - 1;
if(leapyear)
{
int const ml[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31};
for(int i=0; i!=result->tm_mon; ++i)
result->tm_yday += ml[i];
}
else
{
int const ml[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31};
for(int i=0; i!=result->tm_mon; ++i)
result->tm_yday += ml[i];
}
/* MSVC8 implementation always does that, using a German MS
Windows XP,
not sure if that is correct... */
result->tm_isdst = 0;
return result;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5428#comment:3> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC