Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _UNOTOOLS_CALENDARWRAPPER_HXX
21 : : #define _UNOTOOLS_CALENDARWRAPPER_HXX
22 : :
23 : : #include <tools/datetime.hxx>
24 : : #include <tools/string.hxx>
25 : : #include <com/sun/star/uno/Reference.hxx>
26 : : #include <com/sun/star/uno/Sequence.hxx>
27 : : #include <com/sun/star/i18n/Calendar2.hpp>
28 : : #include <com/sun/star/lang/Locale.hpp>
29 : : #include "unotools/unotoolsdllapi.h"
30 : :
31 : : namespace com { namespace sun { namespace star {
32 : : namespace lang {
33 : : class XMultiServiceFactory;
34 : : }
35 : : }}}
36 : :
37 : : namespace com { namespace sun { namespace star {
38 : : namespace i18n {
39 : : class XCalendar3;
40 : : }
41 : : }}}
42 : :
43 : :
44 : : class UNOTOOLS_DLLPUBLIC CalendarWrapper
45 : : {
46 : : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr;
47 : : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCalendar3 > xC;
48 : :
49 : : DateTime aEpochStart; // 1Jan1970
50 : :
51 : : public:
52 : : CalendarWrapper(
53 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF
54 : : );
55 : : ~CalendarWrapper();
56 : :
57 : :
58 : : // wrapper implementations of XCalendar
59 : :
60 : : void loadDefaultCalendar( const ::com::sun::star::lang::Locale& rLocale );
61 : : void loadCalendar( const ::rtl::OUString& rUniqueID, const ::com::sun::star::lang::Locale& rLocale );
62 : : ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const;
63 : : ::rtl::OUString getUniqueID() const;
64 : : /// set UTC date/time
65 : : void setDateTime( double nTimeInDays );
66 : : /// get UTC date/time
67 : : double getDateTime() const;
68 : : /// convenience method to set local date/time
69 : : void setLocalDateTime( double nTimeInDays );
70 : : /// convenience method to get local date/time
71 : : double getLocalDateTime() const;
72 : :
73 : :
74 : : // wrapper implementations of XCalendar
75 : :
76 : : void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue );
77 : : sal_Bool isValid() const;
78 : : sal_Int16 getValue( sal_Int16 nFieldIndex ) const;
79 : : void addValue( sal_Int16 nFieldIndex, sal_Int32 nAmount );
80 : : sal_Int16 getFirstDayOfWeek() const;
81 : : sal_Int16 getNumberOfMonthsInYear() const;
82 : : sal_Int16 getNumberOfDaysInWeek() const;
83 : : String getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const;
84 : :
85 : : /** Convenience method to get timezone offset in milliseconds, taking both
86 : : fields ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS into account. */
87 : : sal_Int32 getZoneOffsetInMillis() const;
88 : : /** Convenience method to get DST offset in milliseconds, taking both
89 : : fields DST_OFFSET and DST_OFFSET_SECOND_MILLIS into account. */
90 : : sal_Int32 getDSTOffsetInMillis() const;
91 : :
92 : :
93 : : // wrapper implementations of XExtendedCalendar
94 : :
95 : : String getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const;
96 : :
97 : :
98 : : // wrapper implementations of XCalendar3
99 : :
100 : : ::com::sun::star::i18n::Calendar2 getLoadedCalendar() const;
101 : : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getDays() const;
102 : : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getMonths() const;
103 : : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getGenitiveMonths() const;
104 : : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getPartitiveMonths() const;
105 : :
106 : :
107 : : // convenience methods
108 : :
109 : : /// get epoch start (should be 01Jan1970)
110 : 386 : inline const DateTime& getEpochStart() const
111 : 386 : { return aEpochStart; }
112 : :
113 : : /// set a local (!) Gregorian DateTime
114 : 251 : inline void setGregorianDateTime( const DateTime& rDateTime )
115 : 251 : { setLocalDateTime( rDateTime - aEpochStart ); }
116 : :
117 : : /// get the DateTime as a local (!) Gregorian DateTime
118 : : inline DateTime getGregorianDateTime() const
119 : : { return aEpochStart + getLocalDateTime(); }
120 : :
121 : : private:
122 : :
123 : : /** get timezone or DST offset in milliseconds, fields are
124 : : CalendarFieldIndex ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS
125 : : respectively DST_OFFSET and DST_OFFSET_SECOND_MILLIS.
126 : : */
127 : : sal_Int32 getCombinedOffsetInMillis( sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const;
128 : : };
129 : :
130 : : #endif
131 : :
132 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|