xref: /AOO41X/main/unotools/inc/unotools/calendarwrapper.hxx (revision bae3752ec30c258ca902793e4eea3c818b0bcaad)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _UNOTOOLS_CALENDARWRAPPER_HXX
25 #define _UNOTOOLS_CALENDARWRAPPER_HXX
26 
27 #include <tools/datetime.hxx>
28 #include <tools/string.hxx>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/i18n/Calendar.hpp>
32 #include <com/sun/star/lang/Locale.hpp>
33 #include "unotools/unotoolsdllapi.h"
34 
35 namespace com { namespace sun { namespace star {
36     namespace lang {
37         class XMultiServiceFactory;
38     }
39 }}}
40 
41 namespace com { namespace sun { namespace star {
42     namespace i18n {
43         class XExtendedCalendar;
44     }
45 }}}
46 
47 
48 class UNOTOOLS_DLLPUBLIC CalendarWrapper
49 {
50     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr;
51     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XExtendedCalendar >   xC;
52 
53             DateTime            aEpochStart;        // 1Jan1970
54 
55 public:
56                                 CalendarWrapper(
57                                     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF
58                                     );
59                                 ~CalendarWrapper();
60 
61 
62     // wrapper implementations of XCalendar
63 
64     void loadDefaultCalendar( const ::com::sun::star::lang::Locale& rLocale );
65     void loadCalendar( const ::rtl::OUString& rUniqueID, const ::com::sun::star::lang::Locale& rLocale );
66     ::com::sun::star::i18n::Calendar getLoadedCalendar() const;
67     ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const;
68     ::rtl::OUString getUniqueID() const;
69     /// set UTC date/time
70     void setDateTime( double nTimeInDays );
71     /// get UTC date/time
72     double getDateTime() const;
73     /// convenience method to set local date/time
74     void setLocalDateTime( double nTimeInDays );
75     /// convenience method to get local date/time
76     double getLocalDateTime() const;
77 
78     // wrapper implementations of XCalendar
79 
80     void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue );
81     sal_Bool isValid() const;
82     sal_Int16 getValue( sal_Int16 nFieldIndex ) const;
83     void addValue( sal_Int16 nFieldIndex, sal_Int32 nAmount );
84     sal_Int16 getFirstDayOfWeek() const;
85     void setFirstDayOfWeek( sal_Int16 nDay );
86     void setMinimumNumberOfDaysForFirstWeek( sal_Int16 nDays );
87     sal_Int16 getMinimumNumberOfDaysForFirstWeek() const;
88     sal_Int16 getNumberOfMonthsInYear() const;
89     sal_Int16 getNumberOfDaysInWeek() const;
90     ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getMonths() const;
91     ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getDays() const;
92     String getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const;
93 
94     /** Convenience method to get timezone offset in milliseconds, taking both
95         fields ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS into account. */
96     sal_Int32 getZoneOffsetInMillis() const;
97     /** Convenience method to get DST offset in milliseconds, taking both
98         fields DST_OFFSET and DST_OFFSET_SECOND_MILLIS into account. */
99     sal_Int32 getDSTOffsetInMillis() const;
100 
101     // wrapper implementations of XExtendedCalendar
102 
103     String getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const;
104 
105 
106     // convenience methods
107 
108     /// get epoch start (should be 01Jan1970)
getEpochStart() const109     inline  const DateTime&     getEpochStart() const
110                                     { return aEpochStart; }
111 
112     /// set a local (!) Gregorian DateTime
setGregorianDateTime(const DateTime & rDateTime)113     inline  void                setGregorianDateTime( const DateTime& rDateTime )
114                                     { setLocalDateTime( rDateTime - aEpochStart ); }
115 
116     /// get the DateTime as a local (!) Gregorian DateTime
getGregorianDateTime() const117     inline  DateTime            getGregorianDateTime() const
118                                     { return aEpochStart + getLocalDateTime(); }
119 
120 private:
121 
122     /** get timezone or DST offset in milliseconds, fields are
123         CalendarFieldIndex ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS
124         respectively DST_OFFSET and DST_OFFSET_SECOND_MILLIS.
125      */
126     sal_Int32 getCombinedOffsetInMillis( sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const;
127 };
128 
129 #endif
130