File indexing completed on 2023-10-03 03:16:24
0001 /* 0002 Copyright (c) 2010 John Layt <john@layt.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KDAYPERIOD_H 0021 #define KDAYPERIOD_H 0022 0023 #include <QSharedDataPointer> 0024 0025 #include "klocale.h" 0026 #include <kdelibs4support_export.h> 0027 0028 class QDate; 0029 class QString; 0030 class QTime; 0031 0032 class KDayPeriodPrivate; 0033 0034 /** 0035 * @internal 0036 * @since 4.6 0037 * 0038 * This class is internal for now but may later be exported if required. 0039 * 0040 * This is a class to implement the CLDR Day Period Rules. 0041 * 0042 * Most commonly this will be used to implement support for the 12 hour clock 0043 * e.g. 00:00:00 to 11:59:59.999 is AM and 12:00:00 to 23:59:59.999 is PM. 0044 * However CLDR Day Period Rules cater for cultures where the day may be divided 0045 * into more periods than just AM/PM. 0046 * See http://www.unicode.org/reports/tr35/tr35-15.html#DayPeriodRules 0047 * 0048 * @b license GNU-LGPL v.2 or later 0049 * 0050 * @see KLocale 0051 * 0052 * @author John Layt <john@layt.net> 0053 */ 0054 class KDayPeriod 0055 { 0056 public: 0057 /** 0058 * Constructs a KDayPeriod for a given time period 0059 * 0060 * @param periodCode the unique code for the period 0061 * @param longName the KLocale::LongName of the Day Period 0062 * @param shortName the KLocale::ShortName of the Day Period 0063 * @param narrowName the KLocale::NarrowName of the Day Period 0064 * @param periodStart the inclusive Start Time of the Day Period 0065 * @param periodEnd the inclusive End Time of the Day Period 0066 * @param offsetFromStart offset of hour in period from the periodStart 0067 * @param offsetIfZero if hour is 0, what should it be converted to 0068 */ 0069 KDayPeriod(const QString &periodCode, 0070 const QString &longName, 0071 const QString &shortName, 0072 const QString &narrowName, 0073 const QTime &periodStart, 0074 const QTime &periodEnd, 0075 int offsetFromStart, 0076 int offsetIfZero); 0077 0078 /** 0079 * Constructs a null KDayPeriod 0080 */ 0081 KDELIBS4SUPPORT_DEPRECATED explicit KDayPeriod(); 0082 0083 /** 0084 * Copy Constructor 0085 * 0086 * @param rhs KDayPeriod to copy 0087 * 0088 */ 0089 KDayPeriod(const KDayPeriod &rhs); 0090 0091 /** 0092 * Destructor. 0093 */ 0094 virtual ~KDayPeriod(); 0095 0096 /** 0097 * Assignment operator 0098 * 0099 * @param rhs KDayPeriod to assign 0100 * 0101 */ 0102 KDayPeriod &operator=(const KDayPeriod &rhs); 0103 0104 /** 0105 * Return the Period Code 0106 * 0107 * @return the Period Code 0108 */ 0109 QString periodCode() const; 0110 0111 /** 0112 * Return the time the Period starts at 0113 * 0114 * @return the time the Period starts 0115 */ 0116 QTime periodStart() const; 0117 0118 /** 0119 * Return the time the Period ends at 0120 * 0121 * @return the time the Period ends 0122 */ 0123 QTime periodEnd() const; 0124 0125 /** 0126 * Return translated Period Name in the required format 0127 * e.g. Ante Meridian, AM or A 0128 * 0129 * @param format the name format to return 0130 * @return the Period Name 0131 */ 0132 QString periodName(KLocale::DateTimeComponentFormat format = KLocale::ShortName) const; 0133 0134 /** 0135 * Calculate and return the hour in the Day Period for a given 24h time. 0136 * 0137 * For example, 17:00 would return 5 in the PM period of the standard 12 hour clock 0138 * 0139 * @param time the time to return the hour for 0140 * @return the Hour in the Day Period 0141 */ 0142 int hourInPeriod(const QTime &time) const; 0143 0144 /** 0145 * Calculate and return the 24hr time for a given hms in the Day Period 0146 * 0147 * For example, 5 in the PM period of the standard 12 hour clock would return 17:00 0148 * 0149 * @param hourInPeriod the hour in the day period 0150 * @param minute the minute in the hour 0151 * @param second the second in the minute 0152 * @param millisecond the millisecond in the second 0153 * @return the Time in the 24hr clock 0154 */ 0155 QTime time(int hourInPeriod, int minute, int second, int millisecond = 0) const; 0156 0157 /** 0158 * Return if the Day Period is valid 0159 * 0160 * @return if the Day Period is valid 0161 */ 0162 bool isValid() const; 0163 0164 /** 0165 * Return if a given time is in the Day Period 0166 * 0167 * @return if the time is valid in the Day Period 0168 */ 0169 bool isValid(const QTime &time) const; 0170 0171 private: 0172 QSharedDataPointer<KDayPeriodPrivate> d; 0173 }; 0174 0175 #endif // KDAYPERIOD_H