Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/unotools/calendarwrapper.hxx
Line
Count
Source
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 INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX
21
#define INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX
22
23
#include <tools/datetime.hxx>
24
#include <com/sun/star/uno/Reference.hxx>
25
#include <unotools/unotoolsdllapi.h>
26
27
namespace com::sun::star::uno { class XComponentContext; }
28
namespace com::sun::star::i18n { class XCalendar4; }
29
namespace com::sun::star::i18n { struct Calendar2; }
30
namespace com::sun::star::i18n { struct CalendarItem2; }
31
namespace com::sun::star::lang { struct Locale; }
32
namespace com::sun::star::uno { template <class E> class Sequence; }
33
34
class UNOTOOLS_DLLPUBLIC CalendarWrapper
35
{
36
    css::uno::Reference< css::i18n::XCalendar4 >   xC;
37
38
    const DateTime aEpochStart;        // 1Jan1970
39
40
public:
41
                                CalendarWrapper(
42
                                    const css::uno::Reference< css::uno::XComponentContext > & rxContext
43
                                    );
44
                                ~CalendarWrapper();
45
46
    // wrapper implementations of XCalendar
47
48
    /** Load the default calendar of a locale.
49
50
        This adds a bool bTimeZoneUTC parameter which is not part of the UNO API to
51
        facilitate handling of non time zone aware data.
52
53
        @param  bTimeZoneUTC
54
                Default <TRUE/>. If <FALSE/>, the system's timezone is assigned
55
                to the calendar, including all DST quirks like not existing
56
                times on DST transition dates when switching to/from DST. As
57
                current implementations and number parser/formatter don't store
58
                or convert or calculate with time zones it is safer to use UTC,
59
                which is not DST afflicted, otherwise surprises are lurking
60
                (for example tdf#92503).
61
     */
62
    void loadDefaultCalendar( const css::lang::Locale& rLocale, bool bTimeZoneUTC = true );
63
    /// This adds a bTimeZoneUTC parameter which is not part of the API.
64
    void loadCalendar( const OUString& rUniqueID, const css::lang::Locale& rLocale, bool bTimeZoneUTC = true );
65
66
    /* XXX NOTE: the time zone taking UNO API functions are not implemented as
67
     * wrapper interface as they are not necessary/used so far. These are:
68
    void loadDefaultCalendarTZ( const css::lang::Locale& rLocale, const OUString& rTimeZone );
69
    void loadCalendarTZ( const OUString& rUniqueID, const css::lang::Locale& rLocale, const OUString& rTimeZone );
70
     */
71
72
    css::uno::Sequence< OUString > getAllCalendars( const css::lang::Locale& rLocale ) const;
73
    OUString getUniqueID() const;
74
    /// set UTC date/time
75
    void setDateTime( double fTimeInDays );
76
    /// get UTC date/time
77
    double getDateTime() const;
78
79
    // For local setDateTime() and getDateTime() see further down at wrapper
80
    // implementations of XCalendar4.
81
82
    // wrapper implementations of XCalendar
83
84
    void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue );
85
    bool isValid() const;
86
    sal_Int16 getValue( sal_Int16 nFieldIndex ) const;
87
    sal_Int16 getFirstDayOfWeek() const;
88
    sal_Int16 getNumberOfMonthsInYear() const;
89
    sal_Int16 getNumberOfDaysInWeek() const;
90
    OUString getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const;
91
92
    // wrapper implementations of XExtendedCalendar
93
94
    OUString getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const;
95
96
    // wrapper implementations of XCalendar3
97
98
    css::i18n::Calendar2 getLoadedCalendar() const;
99
    css::uno::Sequence< css::i18n::CalendarItem2 > getDays() const;
100
    css::uno::Sequence< css::i18n::CalendarItem2 > getMonths() const;
101
    css::uno::Sequence< css::i18n::CalendarItem2 > getGenitiveMonths() const;
102
    css::uno::Sequence< css::i18n::CalendarItem2 > getPartitiveMonths() const;
103
104
    // wrapper implementations of XCalendar4
105
106
    /// set local date/time
107
    void setLocalDateTime( double fTimeInDays );
108
    /// get local date/time
109
    double getLocalDateTime() const;
110
111
    // convenience methods
112
113
    /// get epoch start (should be 01Jan1970)
114
    const DateTime&     getEpochStart() const
115
290k
                                    { return aEpochStart; }
116
117
    /// set a local (!) Gregorian DateTime
118
    void                setGregorianDateTime( const DateTime& rDateTime )
119
161k
                                    { setLocalDateTime( DateTime::Sub( rDateTime, aEpochStart)); }
120
121
};
122
123
#endif
124
125
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */