Kaydet (Commit) f511fee1 authored tarafından Luboš Luňák's avatar Luboš Luňák

adjust for timezone when reading datetime

üst 593ae387
......@@ -74,6 +74,7 @@
#include <rtl/string.h>
#include "FieldTypes.hxx"
#include <tools/datetime.hxx>
#include <tools/string.hxx>
#ifdef DEBUG_DOMAINMAPPER
#include <resourcemodel/QNameToString.hxx>
......@@ -966,24 +967,60 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
util::DateTime lcl_DateStringToDateTime( const ::rtl::OUString& rDateTime )
{
util::DateTime aDateTime;
DateTime aDateTime;
//xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z
//OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
sal_Int32 nIndex = 0;
::rtl::OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
::rtl::OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
int timezonepos = nIndex;
nIndex = 0;
aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
aDateTime.SetYear( sDate.getToken( 0, '-', nIndex ).toInt32() );
aDateTime.SetMonth( sDate.getToken( 0, '-', nIndex ).toInt32() );
aDateTime.SetDay( sDate.copy( nIndex ).toInt32() );
nIndex = 0;
aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
aDateTime.SetHour( sTime.getToken( 0, ':', nIndex ).toInt32() );
aDateTime.SetMin( sTime.getToken( 0, ':', nIndex ).toInt32() );
aDateTime.SetSec( sTime.copy( nIndex ).toInt32() );
return aDateTime;
if( timezonepos >= 0 ) // otherwise consider it local time
{
bool negative = false;
nIndex = timezonepos;
if( nIndex < rDateTime.getLength() && rDateTime[ nIndex ] == '-' )
{
negative = true;
++nIndex;
}
else if ( nIndex < rDateTime.getLength() && rDateTime[ nIndex ] == '+' )
{
++nIndex;
}
Time diff( 0, 0, 0 );
if( nIndex < rDateTime.getLength())
{
diff.SetHour( rDateTime.getToken( 0, ':', nIndex ).toInt32());
diff.SetMin( rDateTime.getToken( 0, ':', nIndex ).toInt32());
}
// convert to utc, then to local
if( negative )
aDateTime -= diff;
else
aDateTime += diff;
aDateTime.ConvertToLocalTime();
}
util::DateTime ret;
ret.Year = aDateTime.GetYear();
ret.Month = aDateTime.GetMonth();
ret.Day = aDateTime.GetDay();
ret.Hours = aDateTime.GetHour();
ret.Minutes = aDateTime.GetMin();
ret.Seconds = aDateTime.GetSec();
ret.HundredthSeconds = 0;
return ret;
}
void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap )
{
uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment