summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2009-01-06 12:54:16 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2009-01-06 12:54:16 +0000
commit4e1fd2fa161708049f1c3b6039659d0bf4f4539e (patch)
tree860f7ec49a96dbb04a3161d44dd1598ce26da2a4 /unotools
parent3dea05ab282d5a8c56f1f8f23210641d3b5d029c (diff)
CWS-TOOLING: integrate CWS locales31
2008-12-10 14:56:44 +0100 er r265193 : calling convention mismatch 2008-12-08 12:04:56 +0100 er r264984 : #i96840# classify some extra languages as CTL 2008-12-05 19:54:02 +0100 erack r264916 : ImpSvNumberformatScan::ScanType: do not miscategorize as automtic currency if currency symbol in General string, such as R in Standard 2008-12-04 12:07:05 +0100 erack r264831 : CWS-TOOLING: rebase CWS locales31 to trunk@264807 (milestone: DEV300:m37) 2008-12-03 16:14:17 +0100 erack r264797 : #i93694# update script+language -> unicode digit mapping; patch from <hdu> 2008-11-25 02:01:18 +0100 erack r264270 : #i83349# apply remaining parts of the patch, now that we use ICU 4.0; contributed by <kstribley> 2008-11-25 01:38:20 +0100 erack r264269 : #i93694# test the bit, not the constant ... 2008-11-24 10:34:58 +0100 erack r264211 : #i93694# LANGUAGE_ARABIC is gone 2008-11-24 01:39:25 +0100 erack r264192 : #i94435# LANGUAGE_SPANISH now is an alias of LANGUAGE_SPANISH_MODERN, need LANGUAGE_SPANISH_DATED in switch case if both are to be used 2008-11-23 22:54:17 +0100 erack r264190 : CWS-TOOLING: rebase CWS locales31 to trunk@263288 (milestone: DEV300:m35) 2008-11-23 20:23:28 +0100 erack r264189 : migrate CWS locales31 to SVN
Diffstat (limited to 'unotools')
-rw-r--r--unotools/inc/unotools/calendarwrapper.hxx19
-rw-r--r--unotools/source/i18n/calendarwrapper.cxx78
2 files changed, 80 insertions, 17 deletions
diff --git a/unotools/inc/unotools/calendarwrapper.hxx b/unotools/inc/unotools/calendarwrapper.hxx
index ad5a898143e4..c98e0867e8fa 100644
--- a/unotools/inc/unotools/calendarwrapper.hxx
+++ b/unotools/inc/unotools/calendarwrapper.hxx
@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: calendarwrapper.hxx,v $
- * $Revision: 1.10 $
+ * $Revision: 1.10.24.1 $
*
* This file is part of OpenOffice.org.
*
@@ -81,6 +81,9 @@ public:
void setLocalDateTime( double nTimeInDays );
/// convenience method to get local date/time
double getLocalDateTime() const;
+
+ // wrapper implementations of XCalendar
+
void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue );
sal_Bool isValid() const;
sal_Int16 getValue( sal_Int16 nFieldIndex ) const;
@@ -95,6 +98,13 @@ public:
::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getDays() const;
String getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const;
+ /** Convenience method to get timezone offset in milliseconds, taking both
+ fields ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS into account. */
+ sal_Int32 getZoneOffsetInMillis() const;
+ /** Convenience method to get DST offset in milliseconds, taking both
+ fields DST_OFFSET and DST_OFFSET_SECOND_MILLIS into account. */
+ sal_Int32 getDSTOffsetInMillis() const;
+
// wrapper implementations of XExtendedCalendar
String getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const;
@@ -114,6 +124,13 @@ public:
inline DateTime getGregorianDateTime() const
{ return aEpochStart + getLocalDateTime(); }
+private:
+
+ /** get timezone or DST offset in milliseconds, fields are
+ CalendarFieldIndex ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS
+ respectively DST_OFFSET and DST_OFFSET_SECOND_MILLIS.
+ */
+ sal_Int32 getCombinedOffsetInMillis( sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const;
};
#endif
diff --git a/unotools/source/i18n/calendarwrapper.cxx b/unotools/source/i18n/calendarwrapper.cxx
index 2c003dc0d620..1d83761b5cea 100644
--- a/unotools/source/i18n/calendarwrapper.cxx
+++ b/unotools/source/i18n/calendarwrapper.cxx
@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: calendarwrapper.cxx,v $
- * $Revision: 1.15 $
+ * $Revision: 1.15.24.1 $
*
* This file is part of OpenOffice.org.
*
@@ -51,6 +51,9 @@ using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::uno;
+const double MILLISECONDS_PER_DAY = 1000.0 * 60.0 * 60.0 * 24.0;
+
+
CalendarWrapper::CalendarWrapper(
const Reference< lang::XMultiServiceFactory > & xSF
)
@@ -259,6 +262,50 @@ double CalendarWrapper::getDateTime() const
}
+sal_Int32 CalendarWrapper::getCombinedOffsetInMillis(
+ sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const
+{
+ sal_Int32 nOffset = 0;
+ try
+ {
+ if ( xC.is() )
+ {
+ nOffset = static_cast<sal_Int32>( xC->getValue( nParentFieldIndex )) * 60000;
+ sal_Int16 nSecondMillis = xC->getValue( nChildFieldIndex );
+ if (nOffset < 0)
+ nOffset -= static_cast<sal_uInt16>( nSecondMillis);
+ else
+ nOffset += static_cast<sal_uInt16>( nSecondMillis);
+ }
+ }
+ catch ( Exception& e )
+ {
+#ifndef PRODUCT
+ ByteString aMsg( "setLocalDateTime: Exception caught\n" );
+ aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+#else
+ (void)e;
+#endif
+ }
+ return nOffset;
+}
+
+
+sal_Int32 CalendarWrapper::getZoneOffsetInMillis() const
+{
+ return getCombinedOffsetInMillis( CalendarFieldIndex::ZONE_OFFSET,
+ CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS);
+}
+
+
+sal_Int32 CalendarWrapper::getDSTOffsetInMillis() const
+{
+ return getCombinedOffsetInMillis( CalendarFieldIndex::DST_OFFSET,
+ CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS);
+}
+
+
void CalendarWrapper::setLocalDateTime( double nTimeInDays )
{
try
@@ -270,22 +317,23 @@ void CalendarWrapper::setLocalDateTime( double nTimeInDays )
// OlsonTimeZone transitions. Since ICU incorporates also
// historical data even the timezone may differ for different
// dates! (Which was the cause for #i76623# when the timezone of a
- // previously set date was used.)
+ // previously set date was used.) Timezone may also include
+ // seconds, so use milliseconds field as well.
xC->setDateTime( nTimeInDays );
- sal_Int16 nZone1 = xC->getValue( CalendarFieldIndex::ZONE_OFFSET );
- sal_Int16 nDST1 = xC->getValue( CalendarFieldIndex::DST_OFFSET );
- double nLoc = nTimeInDays - (double)(nZone1 + nDST1) / 60.0 / 24.0;
+ sal_Int32 nZone1 = getZoneOffsetInMillis();
+ sal_Int32 nDST1 = getDSTOffsetInMillis();
+ double nLoc = nTimeInDays - (double)(nZone1 + nDST1) / MILLISECONDS_PER_DAY;
xC->setDateTime( nLoc );
- sal_Int16 nZone2 = xC->getValue( CalendarFieldIndex::ZONE_OFFSET );
- sal_Int16 nDST2 = xC->getValue( CalendarFieldIndex::DST_OFFSET );
+ sal_Int32 nZone2 = getZoneOffsetInMillis();
+ sal_Int32 nDST2 = getDSTOffsetInMillis();
// If DSTs differ after calculation, we crossed boundaries. Do it
// again, this time using the DST corrected initial value for the
// real local time.
// See also localtime/gmtime conversion pitfalls at
// http://www.erack.de/download/timetest.c
- if ( nZone1 != nZone2 || nDST1 != nDST2 )
+ if ( nDST1 != nDST2 )
{
- nLoc = nTimeInDays - (double)(nZone2 + nDST2) / 60.0 / 24.0;
+ nLoc = nTimeInDays - (double)(nZone2 + nDST2) / MILLISECONDS_PER_DAY;
xC->setDateTime( nLoc );
// #i17222# If the DST onset rule says to switch from 00:00 to
// 01:00 and we tried to set onsetDay 00:00 with DST, the
@@ -293,10 +341,10 @@ void CalendarWrapper::setLocalDateTime( double nTimeInDays )
// want. So once again without DST, resulting in onsetDay
// 01:00 and DST. Yes, this seems to be weird, but logically
// correct.
- sal_Int16 nDST3 = xC->getValue( CalendarFieldIndex::DST_OFFSET );
+ sal_Int32 nDST3 = getDSTOffsetInMillis();
if ( nDST2 != nDST3 && !nDST3 )
{
- nLoc = nTimeInDays - (double)(nZone2 + nDST3) / 60.0 / 24.0;
+ nLoc = nTimeInDays - (double)(nZone2 + nDST3) / MILLISECONDS_PER_DAY;
xC->setDateTime( nLoc );
}
}
@@ -322,11 +370,9 @@ double CalendarWrapper::getLocalDateTime() const
if ( xC.is() )
{
double nTimeInDays = xC->getDateTime();
- sal_Int16 nZone = xC->getValue(
- com::sun::star::i18n::CalendarFieldIndex::ZONE_OFFSET );
- sal_Int16 nDST = xC->getValue(
- com::sun::star::i18n::CalendarFieldIndex::DST_OFFSET );
- nTimeInDays += (double)(nZone + nDST) / 60.0 / 24.0;
+ sal_Int32 nZone = getZoneOffsetInMillis();
+ sal_Int32 nDST = getDSTOffsetInMillis();
+ nTimeInDays += (double)(nZone + nDST) / MILLISECONDS_PER_DAY;
return nTimeInDays;
}
}