You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sc...@apache.org on 2017/08/02 21:14:45 UTC
svn commit: r1803924 - in /xerces/c/trunk: cmake/XercesFunctions.cmake
configure.ac src/xercesc/util/XMLDateTime.cpp
src/xercesc/util/XMLDateTime.hpp
Author: scantor
Date: Wed Aug 2 21:14:44 2017
New Revision: 1803924
URL: http://svn.apache.org/viewvc?rev=1803924&view=rev
Log:
XERCESC-2108 - Add epoch conversion support to XMLDateTime
Modified:
xerces/c/trunk/cmake/XercesFunctions.cmake
xerces/c/trunk/configure.ac
xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp
xerces/c/trunk/src/xercesc/util/XMLDateTime.hpp
Modified: xerces/c/trunk/cmake/XercesFunctions.cmake
URL: http://svn.apache.org/viewvc/xerces/c/trunk/cmake/XercesFunctions.cmake?rev=1803924&r1=1803923&r2=1803924&view=diff
==============================================================================
--- xerces/c/trunk/cmake/XercesFunctions.cmake (original)
+++ xerces/c/trunk/cmake/XercesFunctions.cmake Wed Aug 2 21:14:44 2017
@@ -31,6 +31,8 @@ check_function_exists(socket HAVE_SOCKET
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
check_function_exists(ftime HAVE_FTIME)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+check_function_exists(gmtime_r HAVE_GMTIME_R)
+check_function_exists(timegm HAVE_TIMEGM)
check_function_exists(memmove HAVE_MEMMOVE)
check_function_exists(memset HAVE_MEMSET)
check_function_exists(nl_langinfo HAVE_NL_LANGINFO)
Modified: xerces/c/trunk/configure.ac
URL: http://svn.apache.org/viewvc/xerces/c/trunk/configure.ac?rev=1803924&r1=1803923&r2=1803924&view=diff
==============================================================================
--- xerces/c/trunk/configure.ac (original)
+++ xerces/c/trunk/configure.ac Wed Aug 2 21:14:44 2017
@@ -134,12 +134,12 @@ ACX_PTHREAD
#AC_FUNC_STRTOD
AC_CHECK_FUNCS([getcwd pathconf realpath \
getaddrinfo gethostbyaddr gethostbyname socket \
- clock_gettime ftime gettimeofday \
+ clock_gettime ftime gettimeofday timegm gmtime_r \
memmove memset nl_langinfo setlocale localeconv \
strcasecmp strncasecmp stricmp strnicmp strchr strdup \
strrchr strstr strtol strtoul \
towupper towlower mblen \
- wcsupr wcslwr wcsnicmp wcsicmp \
+ wcsupr wcslwr wcsnicmp wcsicmp \
])
# Some Unix systems, like Gnu Hurd, don't define PATH_MAX
Modified: xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp?rev=1803924&r1=1803923&r2=1803924&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp Wed Aug 2 21:14:44 2017
@@ -23,6 +23,7 @@
// Includes
// ---------------------------------------------------------------------------
#include <stdlib.h>
+#include <stdio.h>
#include <assert.h>
#include <errno.h>
@@ -451,6 +452,52 @@ XMLDateTime::XMLDateTime(const XMLCh* co
setBuffer(aString);
}
+XMLDateTime::XMLDateTime(time_t epoch, bool duration, MemoryManager* const manager)
+: fStart(0)
+, fEnd(0)
+, fBufferMaxLen(0)
+, fMilliSecond(0)
+, fHasTime(false)
+, fBuffer(0)
+, fMemoryManager(manager)
+{
+ if (duration) {
+ bool neg = false;
+ if (epoch < 0) {
+ neg = true;
+ epoch = -epoch;
+ }
+
+ unsigned long days = epoch / 86400;
+ epoch %= 86400;
+ unsigned long hours = epoch / 3600;
+ epoch %= 3600;
+ unsigned long minutes = epoch / 60;
+ epoch %= 60;
+ unsigned long seconds = epoch;
+
+ char timebuf[256];
+ snprintf(timebuf, 256, "%sP%luDT%luH%luM%luS", neg ? "-" : "", days, hours, minutes, seconds);
+
+ XMLCh* timeptr = XMLString::transcode(timebuf);
+ setBuffer(timeptr);
+ XMLString::release(&timeptr);
+ }
+ else {
+#ifndef HAVE_GMTIME_R
+ struct tm* ptime=gmtime(&epoch);
+#else
+ struct tm res;
+ struct tm* ptime=gmtime_r(&epoch,&res);
+#endif
+ char timebuf[32];
+ strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
+ XMLCh* timeptr = XMLString::transcode(timebuf);
+ setBuffer(timeptr);
+ XMLString::release(&timeptr);
+ }
+}
+
// -----------------------------------------------------------------------
// Copy ctor and Assignment operators
// -----------------------------------------------------------------------
@@ -495,6 +542,38 @@ int XMLDateTime::getSign() const
return 0;
}
+time_t XMLDateTime::getEpoch(bool duration) const
+{
+ if (duration) {
+ time_t epoch = getSecond() + (60 * getMinute()) + (3600 * getHour()) + (86400 * getDay());
+ if (getMonth())
+ epoch += (((365 * 4) + 1)/48 * 86400);
+ if (getYear())
+ epoch += 365.25 * 86400;
+ return getSign()!=UTC_NEG ? epoch : -epoch;
+ }
+ else {
+ struct tm t;
+ t.tm_sec=getSecond();
+ t.tm_min=getMinute();
+ t.tm_hour=getHour();
+ t.tm_mday=getDay();
+ t.tm_mon=getMonth()-1;
+ t.tm_year=getYear()-1900;
+ t.tm_isdst=0;
+#if defined(HAVE_TIMEGM)
+ return timegm(&t);
+#elif defined(WIN32)
+ // Windows
+ return mktime(&t) - _timezone;
+#else
+ // Hopefully most others...?
+ return mktime(&t) - timezone;
+#endif
+ }
+}
+
+
// ---------------------------------------------------------------------------
// Parsers
// ---------------------------------------------------------------------------
Modified: xerces/c/trunk/src/xercesc/util/XMLDateTime.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLDateTime.hpp?rev=1803924&r1=1803923&r2=1803924&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLDateTime.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLDateTime.hpp Wed Aug 2 21:14:44 2017
@@ -29,6 +29,8 @@
#include <xercesc/util/SchemaDateTimeException.hpp>
#include <xercesc/util/XMLChar.hpp>
+#include <time.h>
+
XERCES_CPP_NAMESPACE_BEGIN
class XSValue;
@@ -65,6 +67,8 @@ public:
XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XMLDateTime(const XMLCh* const,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
+ XMLDateTime(time_t epoch, bool duration,
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~XMLDateTime();
inline void setBuffer(const XMLCh* const);
@@ -132,6 +136,14 @@ public:
static int compareOrder(const XMLDateTime* const
, const XMLDateTime* const);
+ int getYear() const {return fValue[CentYear];}
+ int getMonth() const {return fValue[Month];}
+ int getDay() const {return fValue[Day];}
+ int getHour() const {return fValue[Hour];}
+ int getMinute() const {return fValue[Minute];}
+ int getSecond() const {return fValue[Second];}
+ time_t getEpoch(bool duration=false) const;
+
/***
* Support for Serialization/De-serialization
***/
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org