You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2019/10/22 13:14:00 UTC
[openoffice] branch AOO418 updated: Fixed date/time conversion,
removed whitespace, fixed typos
This is an automated email from the ASF dual-hosted git repository.
mseidel pushed a commit to branch AOO418
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/AOO418 by this push:
new c1c573a Fixed date/time conversion, removed whitespace, fixed typos
c1c573a is described below
commit c1c573aa7389e1b70cccc1ccbdc2309c16015ca6
Author: mseidel <ms...@apache.org>
AuthorDate: Tue Oct 22 14:17:11 2019 +0200
Fixed date/time conversion, removed whitespace, fixed typos
(cherry picked from commit b1ac0f2df4aac3ede7945662108313b588d58777)
---
.../win32/shlxthandler/util/iso8601_converter.cxx | 249 +++++++++++----------
1 file changed, 125 insertions(+), 124 deletions(-)
diff --git a/main/shell/source/win32/shlxthandler/util/iso8601_converter.cxx b/main/shell/source/win32/shlxthandler/util/iso8601_converter.cxx
index 2c4b68a..4ed470b 100644
--- a/main/shell/source/win32/shlxthandler/util/iso8601_converter.cxx
+++ b/main/shell/source/win32/shlxthandler/util/iso8601_converter.cxx
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,16 +7,16 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
@@ -31,148 +31,149 @@
//-----------------------------------
/* Converts ISO 8601 conform date/time
- represenation to the representation
+ representation to the representation
conforming to the current locale
*/
std::wstring iso8601_date_to_local_date(const std::wstring& isoDate )
{
- const std::wstring CONST_SPACE(L" ");
+ const std::wstring CONST_SPACE(L" ");
::std::wstring ws8601DateTime(isoDate);
- if ( ws8601DateTime.length() == 19 )
- {
- //fill in the SYSTEMTIME structure;
- std::string asDateTime = WStringToString( ws8601DateTime );
- SYSTEMTIME DateTime;
- DateTime.wYear = ( unsigned short )strtol( asDateTime.substr( 0, 4 ).c_str(), NULL, 10 );
- DateTime.wMonth = ( unsigned short )strtol( asDateTime.substr( 5, 2 ).c_str(), NULL, 10 );
- DateTime.wDayOfWeek = 0;
- DateTime.wDay = ( unsigned short )strtol( asDateTime.substr( 8, 2 ).c_str(), NULL, 10 );
- DateTime.wHour = ( unsigned short )strtol( asDateTime.substr( 11,2 ).c_str(), NULL, 10 );
- DateTime.wMinute = ( unsigned short )strtol( asDateTime.substr( 14,2 ).c_str(), NULL, 10 );
- DateTime.wSecond = ( unsigned short )strtol( asDateTime.substr( 17,2 ).c_str(), NULL, 10 );
- DateTime.wMilliseconds = 0;
-
- //get Date info from structure
- WCHAR DateBuffer[ MAX_PATH ];
- int DateSize = GetDateFormatW(
- LOCALE_SYSTEM_DEFAULT,
- 0,
- &DateTime,
- NULL,
- DateBuffer,
- MAX_PATH );
-
- if ( DateSize )
- ws8601DateTime.assign(DateBuffer);
- else
- ws8601DateTime = StringToWString( asDateTime );
-
- //get Time info from structure
- WCHAR TimeBuffer[ MAX_PATH ];
-
- int TimeSize = GetTimeFormatW(
- LOCALE_SYSTEM_DEFAULT,
- 0,
- &DateTime,
- NULL,
- TimeBuffer,
- MAX_PATH );
-
- if ( TimeSize )
- {
- ws8601DateTime.append(L" ");
- ws8601DateTime.append(TimeBuffer);
- }
- else
- ws8601DateTime = StringToWString( asDateTime );
- }
-
- return ws8601DateTime;
+ if ( ws8601DateTime.length() >= 19 )
+ {
+ // fill in the SYSTEMTIME structure;
+ std::string asDateTime = WStringToString( ws8601DateTime );
+ SYSTEMTIME DateTime;
+ DateTime.wYear = ( unsigned short )strtol( asDateTime.substr( 0, 4 ).c_str(), NULL, 10 );
+ DateTime.wMonth = ( unsigned short )strtol( asDateTime.substr( 5, 2 ).c_str(), NULL, 10 );
+ DateTime.wDayOfWeek = 0;
+ DateTime.wDay = ( unsigned short )strtol( asDateTime.substr( 8, 2 ).c_str(), NULL, 10 );
+ DateTime.wHour = ( unsigned short )strtol( asDateTime.substr( 11,2 ).c_str(), NULL, 10 );
+ DateTime.wMinute = ( unsigned short )strtol( asDateTime.substr( 14,2 ).c_str(), NULL, 10 );
+ DateTime.wSecond = ( unsigned short )strtol( asDateTime.substr( 17,2 ).c_str(), NULL, 10 );
+ DateTime.wMilliseconds = 0;
+
+ // get Date info from structure
+ WCHAR DateBuffer[ MAX_PATH ];
+ int DateSize = GetDateFormatW(
+ LOCALE_SYSTEM_DEFAULT,
+ 0,
+ &DateTime,
+ NULL,
+ DateBuffer,
+ MAX_PATH );
+
+ if ( DateSize )
+ ws8601DateTime.assign(DateBuffer);
+ else
+ ws8601DateTime = StringToWString( asDateTime );
+
+ // get Time info from structure
+ WCHAR TimeBuffer[ MAX_PATH ];
+
+ int TimeSize = GetTimeFormatW(
+ LOCALE_SYSTEM_DEFAULT,
+ 0,
+ &DateTime,
+ NULL,
+ TimeBuffer,
+ MAX_PATH );
+
+ if ( TimeSize )
+ {
+ ws8601DateTime.append(L" ");
+ ws8601DateTime.append(TimeBuffer);
+ }
+ else
+ ws8601DateTime = StringToWString( asDateTime );
+ }
+
+ return ws8601DateTime;
}
//------------------------------------
/* Converts ISO 8601 conform duration
representation to the representation
conforming to the current locale
-
+
Expect format PTnHnMnS according to
- ISO 8601 where n is abitrary number
+ ISO 8601 where n is arbitrary number
of digits
*/
std::wstring iso8601_duration_to_local_duration(const std::wstring& iso8601duration)
-{
- std::wstring days;
- std::wstring hours;
- std::wstring minutes;
- std::wstring seconds;
-
- std::wstring::const_iterator iter = iso8601duration.begin();
- std::wstring::const_iterator iter_end = iso8601duration.end();
-
- std::wstring num;
-
- for (/**/; iter != iter_end; ++iter)
- {
- if (isdigit(*iter))
- {
- num += *iter;
- }
- else
- {
- if (*iter == L'D' || *iter == L'd')
- days = num;
- else if (*iter == L'H' || *iter == L'h')
- hours = num;
- else if (*iter == L'M' || *iter == L'm')
- minutes = num;
- else if (*iter == L'S' || *iter == L's')
- seconds = num;
-
- num.clear();
- }
- }
-
- if (days.length() > 0)
- {
- int h = ((_wtoi(days.c_str()) * 24) + _wtoi(hours.c_str()));
- wchar_t buff[10];
- _itow(h, buff, 10);
- hours = buff;
- }
-
-#if defined(_MSC_VER) //&& defined(_M_X64)
- std::wostringstream oss;
- oss << std::setw(2) << std::setfill(wchar_t('0')) << hours << L":" <<
- std::setw(2) << std::setfill(wchar_t('0')) << minutes << L":" <<
- std::setw(2) << std::setfill(wchar_t('0')) << seconds;
- return oss.str();
+{
+ std::wstring days;
+ std::wstring hours;
+ std::wstring minutes;
+ std::wstring seconds;
+
+ std::wstring::const_iterator iter = iso8601duration.begin();
+ std::wstring::const_iterator iter_end = iso8601duration.end();
+
+ std::wstring num;
+
+ for (/**/; iter != iter_end; ++iter)
+ {
+ if (isdigit(*iter))
+ {
+ num += *iter;
+ }
+ else
+ {
+ if (*iter == L'D' || *iter == L'd')
+ days = num;
+ else if (*iter == L'H' || *iter == L'h')
+ hours = num;
+ else if (*iter == L'M' || *iter == L'm')
+ minutes = num;
+ else if (*iter == L'S' || *iter == L's')
+ seconds = num;
+
+ num.clear();
+ }
+ }
+
+ if (days.length() > 0)
+ {
+ int h = ((_wtoi(days.c_str()) * 24) + _wtoi(hours.c_str()));
+ wchar_t buff[10];
+ _itow(h, buff, 10);
+ hours = buff;
+ }
+
+#if defined(_MSC_VER) //&& defined(_M_X64)
+ std::wostringstream oss;
+ oss << std::setw(2) << std::setfill(wchar_t('0')) << hours << L":" <<
+ std::setw(2) << std::setfill(wchar_t('0')) << minutes << L":" <<
+ std::setw(2) << std::setfill(wchar_t('0')) << seconds;
+ return oss.str();
#elif defined( __MINGW32__ )
#define ADD_AS_PREFILLED( st, out ) \
- if ( st.length() == 0 ) \
- out += L"00"; \
- else if ( st.length() == 1 ) \
- out += L"0"; \
- out += st;
-
- std::wstring result;
- ADD_AS_PREFILLED( hours, result )
- result += L":";
- ADD_AS_PREFILLED( minutes, result )
- result += L":";
- ADD_AS_PREFILLED( seconds, result )
-
- return result;
+ if ( st.length() == 0 ) \
+ out += L"00"; \
+ else if ( st.length() == 1 ) \
+ out += L"0"; \
+ out += st;
+
+ std::wstring result;
+ ADD_AS_PREFILLED( hours, result )
+ result += L":";
+ ADD_AS_PREFILLED( minutes, result )
+ result += L":";
+ ADD_AS_PREFILLED( seconds, result )
+
+ return result;
#undef ADD_AS_PREFILLED
/*
#else
- std::wostringstream oss;
- oss << std::setw(2) << std::setfill('0') << hours << L":" <<
- std::setw(2) << std::setfill('0') << minutes << L":" <<
- std::setw(2) << std::setfill('0') << seconds;
- return oss.str();
+ std::wostringstream oss;
+ oss << std::setw(2) << std::setfill('0') << hours << L":" <<
+ std::setw(2) << std::setfill('0') << minutes << L":" <<
+ std::setw(2) << std::setfill('0') << seconds;
+ return oss.str();
*/
-#endif
+#endif
}
+/* vim: set noet sw=4 ts=4: */