[mapguide-commits] r10082 - sandbox/adsk/trunk/Common/Foundation/Data
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Jul 17 19:02:41 PDT 2024
Author: christinebao
Date: 2024-07-17 19:02:40 -0700 (Wed, 17 Jul 2024)
New Revision: 10082
Modified:
sandbox/adsk/trunk/Common/Foundation/Data/DateTime.cpp
sandbox/adsk/trunk/Common/Foundation/Data/DateTime.h
Log:
Support DateTimeOffset.
Modified: sandbox/adsk/trunk/Common/Foundation/Data/DateTime.cpp
===================================================================
--- sandbox/adsk/trunk/Common/Foundation/Data/DateTime.cpp 2024-07-17 11:06:37 UTC (rev 10081)
+++ sandbox/adsk/trunk/Common/Foundation/Data/DateTime.cpp 2024-07-18 02:02:40 UTC (rev 10082)
@@ -120,6 +120,7 @@
/// <summary>
/// Constructs the MgDateTime object based on the specified FDO date time
/// string in the formats:
+/// "TIMESTAMP(OFFSET) 'CCYY-MM-DD hh:mm:ss[.sss]+|-lld'"
/// "TIMESTAMP 'CCYY-MM-DD hh:mm:ss[.sss]'"
/// "DATE 'CCYY-MM-DD'"
/// "TIME 'hh:mm:ss[.sss]'"
@@ -141,11 +142,18 @@
wchar_t buf[MG_MAX_DATE_TIME_BUFFER_LENGTH];
::memset(buf, 0, sizeof(buf));
+ bool isOffset = STRING::npos != fdoDateTime.find(L"OFFSET");
bool isDate = STRING::npos != fdoDateTime.find(L"-");
bool isTime = STRING::npos != fdoDateTime.find(L":");
- if (isDate && isTime)
+ if (isOffset && isDate && isTime)
{
+ numFields = ::swscanf(fdoDateTime.c_str(), L"%s '%d-%d-%d %d:%d:%f%lld'",
+ buf, &m_year, &m_month, &m_day, &m_hour, &m_minute, &seconds, &m_offsetTicks);
+ valid = (8 == numFields);
+ }
+ else if (isDate && isTime)
+ {
numFields = ::swscanf(fdoDateTime.c_str(), L"%s '%d-%d-%d %d:%d:%f'",
buf, &m_year, &m_month, &m_day, &m_hour, &m_minute, &seconds);
valid = (7 == numFields);
@@ -357,6 +365,15 @@
return (-1 != m_year && -1 != m_hour);
}
+///////////////////////////////////////////////////////////////////////////////
+/// <summary>
+/// Returns true if DateTimeOffset is valid, false otherwise.
+/// </summary>
+bool MgDateTime::IsDateTimeOffset()
+{
+ return IsDateTime() && m_offsetTicks != MaxOffset + 1;
+}
+
///<summary>Gets the day component of this object</summary>
///<returns>Returns the day component of this object.</returns>
INT8 MgDateTime::GetDay()
@@ -406,6 +423,13 @@
return m_microsecond;
}
+///<summary>Gets the offsetTicks component of this object</summary>
+///<returns>Returns the offsetTicks component of this object.</returns>
+INT64 MgDateTime::GetOffsetTicks()
+{
+ return m_offsetTicks;
+}
+
///<summary>Sets the day component of this object</summary>
///<param name="day">Day of the month in the range of 1 to 31 inclusive</param>
void MgDateTime::SetDay(INT8 day)
@@ -546,6 +570,26 @@
m_microsecond = microsecond;
}
+///<summary>Sets the offsetTicks component of this object</summary>
+///<param name="offsetTicks">OffsetTicks after microsecond in the range of -60*600000000*14 to 60*600000000*14</param>
+void MgDateTime::SetOffsetTicks(INT64 offsetTicks)
+{
+ if (offsetTicks < MinOffset || offsetTicks > MaxOffset || offsetTicks % TicksPerMinute != 0)
+ {
+ STRING buffer;
+ MgUtil::Int64ToString(offsetTicks, buffer);
+
+ MgStringCollection arguments;
+ arguments.Add(L"1");
+ arguments.Add(buffer);
+
+ throw new MgInvalidArgumentException(L"MgDateTime.SetOffsetTicks",
+ __LINE__, __WFILE__, &arguments, L"MgInvalidOffsetTicks", NULL);
+ }
+
+ m_offsetTicks = offsetTicks;
+}
+
MgDateTime& MgDateTime::operator=(const MgDateTime& dt)
{
if (&dt != this)
@@ -557,6 +601,7 @@
m_minute = dt.m_minute;
m_second = dt.m_second;
m_microsecond = dt.m_microsecond;
+ m_offsetTicks = dt.m_offsetTicks;
}
return *this;
@@ -655,6 +700,7 @@
helper->WriteUINT8((BYTE)m_minute);
helper->WriteUINT8((BYTE)m_second);
helper->WriteUINT32(m_microsecond);
+ helper->WriteINT64(m_offsetTicks);
}
void MgDateTime::Deserialize(MgStream* stream)
@@ -684,11 +730,16 @@
UINT32 val2;
helper->GetUINT32(val2);
m_microsecond = (INT32) val2;
+
+ INT64 val3;
+ helper->GetINT64(val3);
+ m_offsetTicks = (INT64)val3;
}
///----------------------------------------------------------------------------
/// <summary>
/// Returns an FDO date time string in one of these formats:
+/// "TIMESTAMP(OFFSET) 'CCYY-MM-DD hh:mm:ss[.sss]+|-lld'"
/// "TIMESTAMP 'CCYY-MM-DD hh:mm:ss[.sss]'"
/// "DATE 'CCYY-MM-DD'"
/// "TIME 'hh:mm:ss[.sss]'"
@@ -704,10 +755,40 @@
::memset(buf, 0, sizeof(buf));
- if (IsDateTime())
+ if (IsDateTimeOffset())
{
if (0 == m_microsecond)
{
+ ::sprintf(buf, "TIMESTAMP(OFFSET) '%04d-%02d-%02d %02d:%02d:%02d%+lld'",
+ m_year, m_month, m_day, m_hour, m_minute, m_second, m_offsetTicks);
+
+ fdoDateTime = buf;
+ }
+ else
+ {
+ string offset;
+ char buf1[MG_MAX_DATE_TIME_BUFFER_LENGTH];
+ ::memset(buf1, 0, sizeof(buf));
+ ::sprintf(buf1, "%+lld", m_offsetTicks);
+ offset = buf1;
+
+ if (m_microsecond % 1000 == 0) // only report milliseconds for FDO
+ ::sprintf(buf, "TIMESTAMP(OFFSET) '%04d-%02d-%02d %02d:%02d:%02d.%03d",
+ m_year, m_month, m_day, m_hour, m_minute, m_second, m_microsecond / 1000);
+ else
+ ::sprintf(buf, "TIMESTAMP(OFFSET) '%04d-%02d-%02d %02d:%02d:%02d.%06d",
+ m_year, m_month, m_day, m_hour, m_minute, m_second, m_microsecond);
+
+ fdoDateTime = buf;
+ MgUtil::TrimEndingZeros(fdoDateTime);
+ fdoDateTime += offset;
+ fdoDateTime += "'";
+ }
+ }
+ else if (IsDateTime())
+ {
+ if (0 == m_microsecond)
+ {
::sprintf(buf, "TIMESTAMP '%04d-%02d-%02d %02d:%02d:%02d'",
m_year, m_month, m_day, m_hour, m_minute, m_second);
@@ -1110,6 +1191,24 @@
}
}
+void MgDateTime::ValidateDateTimeOffset()
+{
+ ValidateDateTime();
+
+ if (m_offsetTicks < MinOffset || m_offsetTicks > MaxOffset || m_offsetTicks % TicksPerMinute != 0)
+ {
+ STRING buffer;
+ MgUtil::Int64ToString(m_offsetTicks, buffer);
+
+ MgStringCollection arguments;
+ arguments.Add(L"1");
+ arguments.Add(buffer);
+
+ throw new MgInvalidArgumentException(L"MgDateTime.ValidateOffset",
+ __LINE__, __WFILE__, &arguments, L"MgInvalidOffsetTicks", NULL);
+ }
+}
+
void MgDateTime::ValidateDateTime()
{
ValidateDate();
@@ -1224,8 +1323,12 @@
/// </summary>
void MgDateTime::Validate()
{
- if (IsDateTime())
+ if (IsDateTimeOffset())
{
+ ValidateDateTimeOffset();
+ }
+ else if (IsDateTime())
+ {
ValidateDateTime();
}
else if (IsDate())
Modified: sandbox/adsk/trunk/Common/Foundation/Data/DateTime.h
===================================================================
--- sandbox/adsk/trunk/Common/Foundation/Data/DateTime.h 2024-07-17 11:06:37 UTC (rev 10081)
+++ sandbox/adsk/trunk/Common/Foundation/Data/DateTime.h 2024-07-18 02:02:40 UTC (rev 10082)
@@ -295,6 +295,25 @@
INT32 GetMicrosecond(); /// __get, __set
/// \brief
+ /// Gets the offsetTicks component of this object
+ ///
+ /// <!-- Syntax in .Net, Java, and PHP -->
+ /// \htmlinclude DotNetSyntaxTop.html
+ /// int GetOffsetTicks();
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude JavaSyntaxTop.html
+ /// int GetOffsetTicks();
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude PHPSyntaxTop.html
+ /// int GetOffsetTicks();
+ /// \htmlinclude SyntaxBottom.html
+ ///
+ /// \return
+ /// Returns the offsetTicks component of this object.
+ ///
+ INT64 GetOffsetTicks(); /// __get, __set
+
+ /// \brief
/// Sets the day component of this object
/// The Validate method should be called after the date time value has been
/// fully specified by Set methods.
@@ -441,6 +460,27 @@
///
void SetMicrosecond(INT32 microsecond);
+ /// \brief
+ /// Sets the offsetTicks component of this object
+ /// The Validate method should be called after the date time value has been
+ /// fully specified by Set methods.
+ ///
+ /// <!-- Syntax in .Net, Java, and PHP -->
+ /// \htmlinclude DotNetSyntaxTop.html
+ /// void SetOffsetTicks(INT64 offsetTicks);
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude JavaSyntaxTop.html
+ /// void SetOffsetTicks(INT64 offsetTicks);
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude PHPSyntaxTop.html
+ /// void SetOffsetTicks(INT64 offsetTicks);
+ /// \htmlinclude SyntaxBottom.html
+ ///
+ /// \param offsetTicks (INT64)
+ /// OffsetTicks after microseconds in the range of -60*600000000*14 to 60*600000000*14
+ ///
+ void SetOffsetTicks(INT64 offsetTicks);
+
////////////////////////////////////////////////////////////////
/// \brief
/// Validates the date time value. This method should be called
@@ -519,6 +559,25 @@
///
bool IsDateTime();
+ /// \brief
+ /// Determines if this object represents DateTimeOffset values.
+ ///
+ /// <!-- Syntax in .Net, Java, and PHP -->
+ /// \htmlinclude DotNetSyntaxTop.html
+ /// bool IsDateTimeOffset();
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude JavaSyntaxTop.html
+ /// boolean IsDateTimeOffset();
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude PHPSyntaxTop.html
+ /// bool IsDateTimeOffset();
+ /// \htmlinclude SyntaxBottom.html
+ ///
+ /// \return
+ /// Returns true if the DateTimeOffset is valid; otherwise returns false.
+ ///
+ bool IsDateTimeOffset();
+
EXTERNAL_API:
/// \brief
@@ -580,6 +639,7 @@
void SplitSeconds(float seconds);
+ void ValidateDateTimeOffset();
void ValidateDateTime();
void ValidateDate();
void ValidateTime();
@@ -619,6 +679,9 @@
static const INT64 MIN_DATETIME = -50000000000000LL;
static const INT64 TIME_ZERO = -60000000000000LL;
static const INT64 DATE_ZERO = -70000000000000LL;
+ static const INT64 TicksPerMinute = (INT64)600000000;
+ static const INT64 MaxOffset = (INT64)60 * TicksPerMinute * (INT64)14;
+ static const INT64 MinOffset = -MaxOffset;
private:
@@ -629,6 +692,8 @@
INT8 m_minute;
INT8 m_second;
INT32 m_microsecond;
+ // To store offset of FdoDateTime.
+ INT64 m_offsetTicks = MaxOffset + 1;
CLASS_ID:
More information about the mapguide-commits
mailing list