diff options
-rw-r--r-- | unotools/inc/unotools/calendarwrapper.hxx | 18 | ||||
-rw-r--r-- | unotools/source/i18n/calendarwrapper.cxx | 63 |
2 files changed, 73 insertions, 8 deletions
diff --git a/unotools/inc/unotools/calendarwrapper.hxx b/unotools/inc/unotools/calendarwrapper.hxx index 742a93cbfaa7..a381e21ace83 100644 --- a/unotools/inc/unotools/calendarwrapper.hxx +++ b/unotools/inc/unotools/calendarwrapper.hxx @@ -2,9 +2,9 @@ * * $RCSfile: calendarwrapper.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: er $ $Date: 2002-07-25 09:53:17 $ + * last change: $Author: er $ $Date: 2002-09-24 14:05:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -113,8 +113,14 @@ public: ::com::sun::star::i18n::Calendar getLoadedCalendar() const; ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const; ::rtl::OUString getUniqueID() const; + /// set UTC date/time void setDateTime( double nTimeInDays ); + /// get UTC date/time double getDateTime() const; + /// convenience method to set local date/time + void setLocalDateTime( double nTimeInDays ); + /// convenience method to get local date/time + double getLocalDateTime() const; void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ); sal_Bool isValid() const; sal_Int16 getValue( sal_Int16 nFieldIndex ) const; @@ -140,13 +146,13 @@ public: inline const DateTime& getEpochStart() const { return aEpochStart; } - /// set a gregorian DateTime + /// set a local (!) Gregorian DateTime inline void setGregorianDateTime( const DateTime& rDateTime ) - { setDateTime( rDateTime - aEpochStart ); } + { setLocalDateTime( rDateTime - aEpochStart ); } - /// get the DateTime as a gregorian DateTime + /// get the DateTime as a local (!) Gregorian DateTime inline DateTime getGregorianDateTime() const - { return aEpochStart + getDateTime(); } + { return aEpochStart + getLocalDateTime(); } }; 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 <comphelper/componentfactory.hxx> #endif +#ifndef _COM_SUN_STAR_I18N_CALENDARFIELDINDEX_HPP_ +#include <com/sun/star/i18n/CalendarFieldIndex.hpp> +#endif #ifndef _COM_SUN_STAR_I18N_XEXTENDEDCALENDAR_HPP_ #include <drafts/com/sun/star/i18n/XExtendedCalendar.hpp> #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 |