File indexing completed on 2024-05-12 16:59:38

0001 /*
0002     SPDX-FileCopyrightText: 2021 Gary Wang <wzc782970009@gmail.com>
0003     SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <unicode/calendar.h>
0011 #include <unicode/smpdtfmt.h>
0012 
0013 #include <QCalendar>
0014 
0015 class QString;
0016 
0017 class ICUCalendarPrivate
0018 {
0019 public:
0020     /**
0021      * Initialize the Gregorian Calendar, which will be used in date conversion.
0022      */
0023     explicit ICUCalendarPrivate();
0024     virtual ~ICUCalendarPrivate();
0025 
0026     /**
0027      * Returns the value for a given time field in the alternate calendar.
0028      */
0029     int32_t year() const;
0030     int32_t month() const;
0031     int32_t day() const;
0032 
0033     /**
0034      * Returns the date from the alternate calendar.
0035      *
0036      * @return the date from the alternate calendar
0037      */
0038     QCalendar::YearMonthDay date() const;
0039 
0040     /**
0041      * Sets the date in the Gregorian Calendar, and convert the date to
0042      * the alternate calendar.
0043      *
0044      * @param date the Gregorian Calendar's date to be converted
0045      * @return @c true if the date is successfully set, @c false otherwise
0046      */
0047     bool setDate(const QDate &date);
0048 
0049     /**
0050      * Sets the alternate calendar's current time with the given time.
0051      *
0052      * @param time the Gregorian Calendar's time as milliseconds
0053      * @return @c true if the time is successfully set, @c false otherwise
0054      */
0055     bool setTime(double time);
0056 
0057 protected:
0058     /**
0059      * Alternate calendar
0060      */
0061     std::unique_ptr<icu::Calendar> m_calendar;
0062     /**
0063      * Standard ICU4C error code.
0064      */
0065     mutable UErrorCode m_errorCode;
0066 
0067 private:
0068     /**
0069      * Gregorian Calendar
0070      */
0071     const std::unique_ptr<icu::Calendar> m_GregorianCalendar;
0072 };