From 9081dab9fe9c3ca583ca6fbf3a6f946a154f417c Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 24 Sep 2002 13:05:52 +0000 Subject: #102692# add setLocalDateTime(), getLocalDateTime() --- unotools/source/i18n/calendarwrapper.cxx | 63 +++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'unotools/source') diff --git a/unotools/source/i18n/calendarwrapper.cxx b/unotools/source/i18n/calendarwrapper.cxx index feb2156697d7..02f63abbe0a7 100644 --- a/unotools/source/i18n/calendarwrapper.cxx +++ b/unotools/source/i18n/calendarwrapper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: calendarwrapper.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: er $ $Date: 2002-07-25 09:53:57 $ + * last change: $Author: er $ $Date: 2002-09-24 14:05:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,9 @@ #ifndef _COMPHELPER_COMPONENTFACTORY_HXX_ #include #endif +#ifndef _COM_SUN_STAR_I18N_CALENDARFIELDINDEX_HPP_ +#include +#endif #ifndef _COM_SUN_STAR_I18N_XEXTENDEDCALENDAR_HPP_ #include #endif @@ -281,6 +284,62 @@ double CalendarWrapper::getDateTime() const } +void CalendarWrapper::setLocalDateTime( double nTimeInDays ) +{ + try + { + if ( xC.is() ) + { + sal_Int16 nZone = xC->getValue( CalendarFieldIndex::ZONE_OFFSET ); + sal_Int16 nDST1 = xC->getValue( CalendarFieldIndex::DST_OFFSET ); + double nLoc = nTimeInDays - (double)(nZone + nDST1) / 60.0 / 24.0; + xC->setDateTime( nLoc ); + sal_Int16 nDST2 = xC->getValue( i18n::CalendarFieldIndex::DST_OFFSET ); + if ( nDST1 != nDST2 ) + { + nLoc = nTimeInDays - (double)(nZone + nDST2) / 60.0 / 24.0; + xC->setDateTime( nLoc ); + } + } + } + catch ( Exception& e ) + { +#ifndef PRODUCT + ByteString aMsg( "setLocalDateTime: Exception caught\n" ); + aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); + DBG_ERRORFILE( aMsg.GetBuffer() ); +#endif + } +} + + +double CalendarWrapper::getLocalDateTime() const +{ + try + { + 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; + return nTimeInDays; + } + } + catch ( Exception& e ) + { +#ifndef PRODUCT + ByteString aMsg( "getLocalDateTime: Exception caught\n" ); + aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); + DBG_ERRORFILE( aMsg.GetBuffer() ); +#endif + } + return 0.0; +} + + void CalendarWrapper::setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ) { try -- cgit v1.2.3