Boost C++ Libraries: Ticket #5428: No <ctime> function in Windows CE 6.0 https://svn.boost.org/trac10/ticket/5428 <p> Windows CE platform is nothing &lt;ctime&gt; function. example std::localtime, std::gmtime, etc... </p> <p> boost/date_time/c_time.hpp is direct use "std::localtime", "std::gmtime". this problem solution is make alternative implementation. </p> <p> Windows CE platform &lt;ctime&gt; sample implementation is there: OpenTimeCE. (I cant paste URL, as spam...) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5428 Trac 1.4.3 zerhud@… Mon, 16 May 2011 08:31:42 GMT <link>https://svn.boost.org/trac10/ticket/5428#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:1</guid> <description> <p> SQLite3 do this (#if SQLITE_OS_WINCE) </p> <pre class="wiki">struct tm *__cdecl localtime(const time_t *t) { static struct tm y; FILETIME uTm, lTm; SYSTEMTIME pTm; sqlite3_int64 t64; t64 = *t; t64 = (t64 + 11644473600)*10000000; uTm.dwLowDateTime = (DWORD)(t64 &amp; 0xFFFFFFFF); uTm.dwHighDateTime= (DWORD)(t64 &gt;&gt; 32); FileTimeToLocalFileTime(&amp;uTm,&amp;lTm); FileTimeToSystemTime(&amp;lTm,&amp;pTm); y.tm_year = pTm.wYear - 1900; y.tm_mon = pTm.wMonth - 1; y.tm_wday = pTm.wDayOfWeek; y.tm_mday = pTm.wDay; y.tm_hour = pTm.wHour; y.tm_min = pTm.wMinute; y.tm_sec = pTm.wSecond; return &amp;y; } </pre> </description> <category>Ticket</category> </item> <item> <author>Ulrich Eckhardt <ulrich.eckhardt@…></author> <pubDate>Wed, 11 Jan 2012 16:14:47 GMT</pubDate> <title>cc, keywords set https://svn.boost.org/trac10/ticket/5428#comment:2 https://svn.boost.org/trac10/ticket/5428#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">ulrich.eckhardt@…</span> added </li> <li><strong>keywords</strong> wince added </li> </ul> <p> Instead of providing a thread-unsafe localtime() implementation, the above could be modified to provide a thread-safe one that could be used for all win32 implementations. Since I'm pondering the same problems for my 1.48 migration, I'll take a look if I can't fix this. </p> Ticket Ulrich Eckhardt <ulrich.eckhardt@…> Mon, 30 Jan 2012 17:45:43 GMT <link>https://svn.boost.org/trac10/ticket/5428#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:3</guid> <description> <p> 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. </p> <p> 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. </p> <p> I'm a bit unsure if I can simply set the tm_isdst to zero for gmtime(), maybe someone else could jump in here. </p> <pre class="wiki"> //! 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&lt;int64_t&gt;(*t); t64 += 11644473600; t64 *= 10000000; // convert to FILETIME struct FILETIME utc_time; utc_time.dwLowDateTime = static_cast&lt;DWORD&gt;(t64 &amp; 0xFFFFFFFF); utc_time.dwHighDateTime= static_cast&lt;DWORD&gt;(t64 &gt;&gt; 32); // split into year, month, day etc SYSTEMTIME st; if(!FileTimeToSystemTime(&amp;utc_time, &amp;st)) boost::throw_exception(std::runtime_error("could not convert calendar time to local time")); result-&gt;tm_year = st.wYear - 1900; result-&gt;tm_mon = st.wMonth - 1; result-&gt;tm_wday = st.wDayOfWeek; result-&gt;tm_mday = st.wDay; result-&gt;tm_hour = st.wHour; result-&gt;tm_min = st.wMinute; result-&gt;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-&gt;tm_yday = result-&gt;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-&gt;tm_mon; ++i) result-&gt;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-&gt;tm_mon; ++i) result-&gt;tm_yday += ml[i]; } /* MSVC8 implementation always does that, using a German MS Windows XP, not sure if that is correct... */ result-&gt;tm_isdst = 0; return result; } </pre> </description> <category>Ticket</category> </item> <item> <author>Ulrich Eckhardt <ulrich.eckhardt@…></author> <pubDate>Wed, 01 Feb 2012 16:56:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5428#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:4</guid> <description> <p> Short update: Another function missing from both CE5 and CE6 is time(). This function is used in boost/date_time/date_clock_device.hpp and boost/date_time/time_clock.hpp. Both uses are inside of template code, so the lack of these functions isn't obvious until the templates are instantiated. </p> <p> My plan is to create a patch that adds a wrapper for time() to the c_time class and redirect any direct uses of time() there. Then, in a second step, I can implement the time wrapper there for CE. I'll post it in two steps because the first step will affect all platforms and I want that step to be as small and clear as possible, hopefully increasing the chances for it to be applied. </p> <p> Notes: </p> <ul><li>I don't have any environments earlier than CE5 here, so I can't speak for those, but I'm assuming that the state of the time functions is the same. </li><li>There are no definitions of time() etc in CE5 and CE6, see e.g. this <a class="ext-link" href="http://blogs.msdn.com/b/cenet/archive/2006/04/29/time-h-on-windows-ce.aspx"><span class="icon">​</span>blog posting</a> of one of the CE developers. </li><li>In CE5 you have declarations in time.h, which are imported by STLport into namespace std, in CE6 those are gone, too. </li></ul> </description> <category>Ticket</category> </item> <item> <author>Ulrich Eckhardt <ulrich.eckhardt@…></author> <pubDate>Wed, 01 Feb 2012 17:26:40 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5428 https://svn.boost.org/trac10/ticket/5428 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost central time wrapper.patch</span> </li> </ul> <p> add central point for time() workarounds </p> Ticket Ulrich Eckhardt <ulrich.eckhardt@…> Wed, 01 Feb 2012 17:41:20 GMT <link>https://svn.boost.org/trac10/ticket/5428#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:5</guid> <description> <p> The attached patch is step 1. It adds a time() function to c_time, which currently only forwards to std::time(). All uses of std::time() in date_time were replaced with calls to that wrapper function. </p> <p> I did two more things: </p> <ol><li>In c_time.hpp were a few tabs and some foobar'd formatting, which I fixed along the way. There also were two misleading comments <code>#else // BOOST_HAS_THREADS</code> which I simply removed. </li><li>In the four cases where time() was used, it was used like <code> time_t t; time(&amp;t);</code> which I replaced with a single line <code>time_t t = time(0);</code>. I was even wondering if I shouldn't drop the pointer argument completely from the wrapper, it seems of little use to me. </li></ol><p> I'd be happy about some feedback whether these changes are acceptable. I'll send the second step implementing c_time::time() for CE tomorrow, I still need to clean it up a bit. </p> </description> <category>Ticket</category> </item> <item> <author>Ulrich Eckhardt <ulrich.eckhardt@…></author> <pubDate>Fri, 03 Feb 2012 10:21:56 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5428 https://svn.boost.org/trac10/ticket/5428 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost time functions for CE.patch</span> </li> </ul> <p> implementations of time(), localtime(), gmtime() for CE </p> Ticket Ulrich Eckhardt <ulrich.eckhardt@…> Fri, 03 Feb 2012 10:34:32 GMT <link>https://svn.boost.org/trac10/ticket/5428#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:6</guid> <description> <p> This second patch adds implementations of the missing functions to c_time. With the exception of the tests relying on serialization, I have run all unit tests on a CE6 system without additional failures when compared to the desktop win32 version. Note that all this is based on 1.48, though the files in question haven't changed in trunk, AFAICT. </p> </description> <category>Ticket</category> </item> <item> <author>Ulrich Eckhardt <ulrich.eckhardt@…></author> <pubDate>Fri, 03 Feb 2012 11:26:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5428#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5428#comment:7</guid> <description> <p> I just verified that the unit tests also succeed under CE5. </p> </description> <category>Ticket</category> </item> </channel> </rss>