Debian Codegraph @

kysdk-qtwidgets/src/klunarcalendarinfo.cpp

raw
1 /*
2 * libkysdk-qtwidgets's Library
3 *
4 * Copyright (C) 2024, KylinSoft Co., Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors: Zhenyu Wang <[email protected]>
20 *
21 */
22
23 #pragma execution_character_set("utf-8")
24 #include "klunarcalendarinfo.h"
25 #include "qmutex.h"
26 #include <QSettings>
27 #include <QTimer>
28 #include <QToolButton>
29 #define year_2099
30
31 namespace kdk
32 {
33 QScopedPointer<KLunarCalendarInfo> KLunarCalendarInfo::self;
34 class KLunarCalendarInfoPrivate : public QObject
35 {
36 Q_DECLARE_PUBLIC(KLunarCalendarInfo)
37 Q_OBJECT
38 public:
39 KLunarCalendarInfoPrivate(KLunarCalendarInfo *parent);
40
41 private:
42 KLunarCalendarInfo *q_ptr;
43 QList<int> lunarCalendarTable; // 农历年表
44 QList<int> springFestival; // 春节公历日期
45 QList<int> lunarData; // 农历每月数据
46 QList<int> chineseTwentyFourData; // 农历二十四节气数据
47 QList<int> monthAdd; // 公历每月前面的天数
48
49 QList<QString> listDayName; // 农历日期名称集合
50 QList<QString> listMonthName; // 农历月份名称集合
51 QList<QString> listSolarTerm; // 二十四节气名称集合
52
53 QList<QString> listTianGan; // 天干名称集合
54 QList<QString> listDiZhi; // 地支名称集合
55 QList<QString> listShuXiang; // 属相名称集合
56 };
57
58 KLunarCalendarInfoPrivate::KLunarCalendarInfoPrivate(KLunarCalendarInfo *parent)
59 : q_ptr(parent)
60 {
61 Q_Q(KLunarCalendarInfo);
62 // 农历查表
63 lunarCalendarTable << 0x04AE53 << 0x0A5748 << 0x5526BD << 0x0D2650 << 0x0D9544 << 0x46AAB9 << 0x056A4D << 0x09AD42 << 0x24AEB6 << 0x04AE4A; // 1901-1910
64 lunarCalendarTable << 0x6A4DBE << 0x0A4D52 << 0x0D2546 << 0x5D52BA << 0x0B544E << 0x0D6A43 << 0x296D37 << 0x095B4B << 0x749BC1 << 0x049754; // 1911-1920
65 lunarCalendarTable << 0x0A4B48 << 0x5B25BC << 0x06A550 << 0x06D445 << 0x4ADAB8 << 0x02B64D << 0x095742 << 0x2497B7 << 0x04974A << 0x664B3E; // 1921-1930
66 lunarCalendarTable << 0x0D4A51 << 0x0EA546 << 0x56D4BA << 0x05AD4E << 0x02B644 << 0x393738 << 0x092E4B << 0x7C96BF << 0x0C9553 << 0x0D4A48; // 1931-1940
67 lunarCalendarTable << 0x6DA53B << 0x0B554F << 0x056A45 << 0x4AADB9 << 0x025D4D << 0x092D42 << 0x2C95B6 << 0x0A954A << 0x7B4ABD << 0x06CA51; // 1941-1950
68 lunarCalendarTable << 0x0B5546 << 0x555ABB << 0x04DA4E << 0x0A5B43 << 0x352BB8 << 0x052B4C << 0x8A953F << 0x0E9552 << 0x06AA48 << 0x6AD53C; // 1951-1960
69 lunarCalendarTable << 0x0AB54F << 0x04B645 << 0x4A5739 << 0x0A574D << 0x052642 << 0x3E9335 << 0x0D9549 << 0x75AABE << 0x056A51 << 0x096D46; // 1961-1970
70 lunarCalendarTable << 0x54AEBB << 0x04AD4F << 0x0A4D43 << 0x4D26B7 << 0x0D254B << 0x8D52BF << 0x0B5452 << 0x0B6A47 << 0x696D3C << 0x095B50; // 1971-1980
71 lunarCalendarTable << 0x049B45 << 0x4A4BB9 << 0x0A4B4D << 0xAB25C2 << 0x06A554 << 0x06D449 << 0x6ADA3D << 0x0AB651 << 0x093746 << 0x5497BB; // 1981-1990
72 lunarCalendarTable << 0x04974F << 0x064B44 << 0x36A537 << 0x0EA54A << 0x86B2BF << 0x05AC53 << 0x0AB647 << 0x5936BC << 0x092E50 << 0x0C9645; // 1991-2000
73 lunarCalendarTable << 0x4D4AB8 << 0x0D4A4C << 0x0DA541 << 0x25AAB6 << 0x056A49 << 0x7AADBD << 0x025D52 << 0x092D47 << 0x5C95BA << 0x0A954E; // 2001-2010
74 lunarCalendarTable << 0x0B4A43 << 0x4B5537 << 0x0AD54A << 0x955ABF << 0x04BA53 << 0x0A5B48 << 0x652BBC << 0x052B50 << 0x0A9345 << 0x474AB9; // 2011-2020
75 lunarCalendarTable << 0x06AA4C << 0x0AD541 << 0x24DAB6 << 0x04B64A << 0x69573D << 0x0A4E51 << 0x0D2646 << 0x5E933A << 0x0D534D << 0x05AA43; // 2021-2030
76 lunarCalendarTable << 0x36B537 << 0x096D4B << 0xB4AEBF << 0x04AD53 << 0x0A4D48 << 0x6D25BC << 0x0D254F << 0x0D5244 << 0x5DAA38 << 0x0B5A4C; // 2031-2040
77 lunarCalendarTable << 0x056D41 << 0x24ADB6 << 0x049B4A << 0x7A4BBE << 0x0A4B51 << 0x0AA546 << 0x5B52BA << 0x06D24E << 0x0ADA42 << 0x355B37; // 2041-2050
78 lunarCalendarTable << 0x09374B << 0x8497C1 << 0x049753 << 0x064B48 << 0x66A53C << 0x0EA54F << 0x06B244 << 0x4AB638 << 0x0AAE4C << 0x092E42; // 2051-2060
79 lunarCalendarTable << 0x3C9735 << 0x0C9649 << 0x7D4ABD << 0x0D4A51 << 0x0DA545 << 0x55AABA << 0x056A4E << 0x0A6D43 << 0x452EB7 << 0x052D4B; // 2061-2070
80 lunarCalendarTable << 0x8A95BF << 0x0A9553 << 0x0B4A47 << 0x6B553B << 0x0AD54F << 0x055A45 << 0x4A5D38 << 0x0A5B4C << 0x052B42 << 0x3A93B6; // 2071-2080
81 lunarCalendarTable << 0x069349 << 0x7729BD << 0x06AA51 << 0x0AD546 << 0x54DABA << 0x04B64E << 0x0A5743 << 0x452738 << 0x0D264A << 0x8E933E; // 2081-2090
82 lunarCalendarTable << 0x0D5252 << 0x0DAA47 << 0x66B53B << 0x056D4F << 0x04AE45 << 0x4A4EB9 << 0x0A4D4C << 0x0D1541 << 0x2D92B5; // 2091-2099
83
84 // 每年春节对应的公历日期
85 springFestival << 130 << 217 << 206; // 1968 1969 1970
86 springFestival << 127 << 215 << 203 << 123 << 211 << 131 << 218 << 207 << 128 << 216; // 1971--1980
87 springFestival << 205 << 125 << 213 << 202 << 220 << 209 << 219 << 217 << 206 << 127; // 1981--1990
88 springFestival << 215 << 204 << 123 << 210 << 131 << 219 << 207 << 128 << 216 << 205; // 1991--2000
89 springFestival << 124 << 212 << 201 << 122 << 209 << 129 << 218 << 207 << 126 << 214; // 2001--2010
90 springFestival << 203 << 123 << 210 << 131 << 219 << 208 << 128 << 216 << 205 << 125; // 2011--2020
91 springFestival << 212 << 201 << 122 << 210 << 129 << 217 << 206 << 126 << 213 << 203; // 2021--2030
92 springFestival << 123 << 211 << 131 << 219 << 208 << 128 << 215 << 204 << 124 << 212; // 2031--2040
93
94 // 16--18位表示闰几月 0--12位表示农历每月的数据 高位表示1月 低位表示12月(农历闰月就会多一个月)
95 lunarData << 461653 << 1386 << 2413; // 1968 1969 1970
96 lunarData << 330077 << 1197 << 2637 << 268877 << 3365 << 531109 << 2900 << 2922 << 398042 << 2395; // 1971--1980
97 lunarData << 1179 << 267415 << 2635 << 661067 << 1701 << 1748 << 398772 << 2742 << 2391 << 330031; // 1981--1990
98 lunarData << 1175 << 1611 << 200010 << 3749 << 527717 << 1452 << 2742 << 332397 << 2350 << 3222; // 1991--2000
99 lunarData << 268949 << 3402 << 3493 << 133973 << 1386 << 464219 << 605 << 2349 << 334123 << 2709; // 2001--2010
100 lunarData << 2890 << 267946 << 2773 << 592565 << 1210 << 2651 << 395863 << 1323 << 2707 << 265877; // 2011--2020
101 lunarData << 1706 << 2773 << 133557 << 1206 << 398510 << 2638 << 3366 << 335142 << 3411 << 1450; // 2021--2030
102 lunarData << 200042 << 2413 << 723293 << 1197 << 2637 << 399947 << 3365 << 3410 << 334676 << 2906; // 2031--2040
103
104 // 二十四节气表
105 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1970
106 chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x97 << 0x97 << 0x78 << 0x79 << 0x79 << 0x69 << 0x78 << 0x77; // 1971
107 chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1972
108 chineseTwentyFourData << 0xA5 << 0xB5 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1973
109 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1974
110 chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x97 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1975
111 chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x89 << 0x88 << 0x78 << 0x87 << 0x87; // 1976
112 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 1977
113 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 1978
114 chineseTwentyFourData << 0x96 << 0xB4 << 0x96 << 0xA6 << 0x96 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1979
115 chineseTwentyFourData << 0x96 << 0xA4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1980
116 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x77 << 0x87; // 1981
117 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1982
118 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x78 << 0x79 << 0x78 << 0x69 << 0x78 << 0x77; // 1983
119 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1984
120 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 1985
121 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1986
122 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x79 << 0x78 << 0x69 << 0x78 << 0x87; // 1987
123 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1988
124 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1989
125 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 1990
126 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x86 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1991
127 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1992
128 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1993
129 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1994
130 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x76 << 0x78 << 0x69 << 0x78 << 0x87; // 1995
131 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 1996
132 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 1997
133 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 1998
134 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 1999
135 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2000
136 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2001
137 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2002
138 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2003
139 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2004
140 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2005
141 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2006
142 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2007
143 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2008
144 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2009
145 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2010
146 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 2011
147 chineseTwentyFourData << 0x96 << 0xB4 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2012
148 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2013
149 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2014
150 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2015
151 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2016
152 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2017
153 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2018
154 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2019
155 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2020
156 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2021
157 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2022
158 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2023
159 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2024
160 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2025
161 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2026
162 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2027
163 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2028
164 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2029
165 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2030
166 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2031
167 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2032
168 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2033
169 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x78 << 0x88 << 0x78 << 0x87 << 0x87; // 2034
170 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2035
171 chineseTwentyFourData << 0x95 << 0xB4 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2036
172 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2037
173 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2038
174 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2039
175 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x69 << 0x78 << 0x87; // 2040
176 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2041
177 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2042
178 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2043
179 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x97 << 0x88 << 0x78 << 0x78 << 0x79 << 0x78 << 0x87; // 2044
180 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2045
181 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2046
182 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2047
183 chineseTwentyFourData << 0x95 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2048
184 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2049
185 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2050
186 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2051
187 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2052
188 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2053
189 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2054
190 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2055
191 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x79 << 0x77 << 0x87; // 2056
192 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2057
193 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2058
194 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2059
195 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2060
196 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2061
197 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2062
198 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2063
199 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0x96 << 0x96 << 0x88 << 0x78 << 0x78 << 0x78 << 0x87 << 0x87; // 2064
200 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2065
201 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2066
202 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2067
203 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2068
204 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2069
205 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2070
206 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2071
207 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2072
208 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x88 << 0x87 << 0x96; // 2073
209 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA5 << 0xA6 << 0x87 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2074
210 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2075
211 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2076
212 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x88 << 0x87 << 0x96; // 2077
213 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x88 << 0x87 << 0x78 << 0x87 << 0x86; // 2078
214 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2079
215 chineseTwentyFourData << 0xA5 << 0xB4 << 0x96 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x78 << 0x78 << 0x87 << 0x87; // 2080
216 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x86 << 0x96; // 2081
217 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2082
218 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2083
219 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA6 << 0xA5 << 0xA6 << 0x96 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2084
220 chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x86 << 0x96; // 2085
221 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x86; // 2086
222 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2087
223 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2088
224 chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x88 << 0x96 << 0x96; // 2089
225 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2090
226 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2091
227 chineseTwentyFourData << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2092
228 chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x87 << 0x87 << 0x87 << 0x96 << 0x96; // 2093
229 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2094
230 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2095
231 chineseTwentyFourData << 0xA5 << 0xB3 << 0xA5 << 0xA5 << 0xA6 << 0xA6 << 0x88 << 0x88 << 0x88 << 0x78 << 0x87 << 0x87; // 2096
232 chineseTwentyFourData << 0xB4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA5 << 0x97 << 0x97 << 0x87 << 0x87 << 0x96 << 0x96; // 2097
233 chineseTwentyFourData << 0xA4 << 0xC3 << 0xA5 << 0xB4 << 0xA5 << 0xA6 << 0x97 << 0x87 << 0x87 << 0x78 << 0x87 << 0x96; // 2098
234 chineseTwentyFourData << 0xA5 << 0xC3 << 0xA5 << 0xB5 << 0xA6 << 0xA6 << 0x87 << 0x88 << 0x88 << 0x78 << 0x87 << 0x86; // 2099
235
236 // 公历每月前面的天数
237 monthAdd << 0 << 31 << 59 << 90 << 120 << 151 << 181 << 212 << 243 << 273 << 304 << 334;
238
239 // 农历日期名称
240 listDayName << "*"
241 << "初一"
242 << "初二"
243 << "初三"
244 << "初四"
245 << "初五"
246 << "初六"
247 << "初七"
248 << "初八"
249 << "初九"
250 << "初十"
251 << "十一"
252 << "十二"
253 << "十三"
254 << "十四"
255 << "十五"
256 << "十六"
257 << "十七"
258 << "十八"
259 << "十九"
260 << "二十"
261 << "廿一"
262 << "廿二"
263 << "廿三"
264 << "廿四"
265 << "廿五"
266 << "廿六"
267 << "廿七"
268 << "廿八"
269 << "廿九"
270 << "三十";
271
272 // 农历月份名称
273 listMonthName << "*"
274 << "正月"
275 << "二月"
276 << "三月"
277 << "四月"
278 << "五月"
279 << "六月"
280 << "七月"
281 << "八月"
282 << "九月"
283 << "十月"
284 << "冬月"
285 << "腊月";
286
287 // 二十四节气名称
288 listSolarTerm << "小寒"
289 << "大寒"
290 << "立春"
291 << "雨水"
292 << "惊蛰"
293 << "春分"
294 << "清明"
295 << "谷雨"
296 << "立夏"
297 << "小满"
298 << "芒种"
299 << "夏至"
300 << "小暑"
301 << "大暑"
302 << "立秋"
303 << "处暑"
304 << "白露"
305 << "秋分"
306 << "寒露"
307 << "霜降"
308 << "立冬"
309 << "小雪"
310 << "大雪"
311 << "冬至";
312
313 // 天干
314 listTianGan << "甲"
315 << "乙"
316 << "丙"
317 << "丁"
318 << "戊"
319 << "己"
320 << "庚"
321 << "辛"
322 << "壬"
323 << "癸";
324
325 // 地支
326 listDiZhi << "子"
327 << "丑"
328 << "寅"
329 << "卯"
330 << "辰"
331 << "巳"
332 << "午"
333 << "未"
334 << "申"
335 << "酉"
336 << "戌"
337 << "亥";
338
339 // 属相
340 listShuXiang << "鼠"
341 << "牛"
342 << "虎"
343 << "兔"
344 << "龙"
345 << "蛇"
346 << "马"
347 << "羊"
348 << "猴"
349 << "鸡"
350 << "狗"
351 << "猪";
352 }
353
354 KLunarCalendarInfo *KLunarCalendarInfo::Instance()
355 {
356 if (self.isNull()) {
357 static QMutex mutex;
358 QMutexLocker locker(&mutex);
359
360 if (self.isNull()) {
361 self.reset(new KLunarCalendarInfo);
362 }
363 }
364
365 return self.data();
366 }
367
368 KLunarCalendarInfo::KLunarCalendarInfo(QObject *parent)
369 : QObject(parent)
370 , d_ptr(new KLunarCalendarInfoPrivate(this))
371 {
372 Q_D(KLunarCalendarInfo);
373 }
374
375 // 计算是否闰年
376 bool KLunarCalendarInfo::isLoopYear(int year)
377 {
378 Q_D(KLunarCalendarInfo);
379 return (((0 == (year % 4)) && (0 != (year % 100))) || (0 == (year % 400)));
380 }
381
382 // 计算指定年月该月共多少天
383 int KLunarCalendarInfo::getMonthDays(int year, int month)
384 {
385 Q_D(KLunarCalendarInfo);
386 int countDay = 0;
387 int loopDay = isLoopYear(year) ? 1 : 0;
388
389 switch (month) {
390 case 1:
391 countDay = 31;
392 break;
393
394 case 2:
395 countDay = 28 + loopDay;
396 break;
397
398 case 3:
399 countDay = 31;
400 break;
401
402 case 4:
403 countDay = 30;
404 break;
405
406 case 5:
407 countDay = 31;
408 break;
409
410 case 6:
411 countDay = 30;
412 break;
413
414 case 7:
415 countDay = 31;
416 break;
417
418 case 8:
419 countDay = 31;
420 break;
421
422 case 9:
423 countDay = 30;
424 break;
425
426 case 10:
427 countDay = 31;
428 break;
429
430 case 11:
431 countDay = 30;
432 break;
433
434 case 12:
435 countDay = 31;
436 break;
437
438 default:
439 countDay = 30;
440 break;
441 }
442
443 return countDay;
444 }
445
446 // 计算指定年月对应到该月共多少天
447 int KLunarCalendarInfo::getTotalMonthDays(int year, int month)
448 {
449 Q_D(KLunarCalendarInfo);
450 int countDay = 0;
451 int loopDay = isLoopYear(year) ? 1 : 0;
452
453 switch (month) {
454 case 1:
455 countDay = 0;
456 break;
457
458 case 2:
459 countDay = 31;
460 break;
461
462 case 3:
463 countDay = 59 + loopDay;
464 break;
465
466 case 4:
467 countDay = 90 + loopDay;
468 break;
469
470 case 5:
471 countDay = 120 + loopDay;
472 break;
473
474 case 6:
475 countDay = 151 + loopDay;
476 break;
477
478 case 7:
479 countDay = 181 + loopDay;
480 break;
481
482 case 8:
483 countDay = 212 + loopDay;
484 break;
485
486 case 9:
487 countDay = 243 + loopDay;
488 break;
489
490 case 10:
491 countDay = 273 + loopDay;
492 break;
493
494 case 11:
495 countDay = 304 + loopDay;
496 break;
497
498 case 12:
499 countDay = 334 + loopDay;
500 break;
501
502 default:
503 countDay = 0;
504 break;
505 }
506
507 return countDay;
508 }
509
510 // 计算指定年月对应星期几
511 int KLunarCalendarInfo::getFirstDayOfWeek(int year, int month, bool FirstDayisSun)
512 {
513 Q_D(KLunarCalendarInfo);
514 int week = 0;
515 week = (year + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7;
516 week += getTotalMonthDays(year, month);
517 week = week % 7 - (!FirstDayisSun);
518
519 if (week == -1)
520 week = 6;
521
522 return week;
523 }
524
525 // 计算国际节日
526 QString KLunarCalendarInfo::getHoliday(int month, int day)
527 {
528 Q_D(KLunarCalendarInfo);
529 int temp = (month << 8) | day;
530 QString strHoliday;
531
532 switch (temp) {
533 case 0x0101:
534 strHoliday = "元旦";
535 break;
536
537 case 0x020E:
538 strHoliday = "情人节";
539 break;
540
541 case 0x0305:
542 strHoliday = "志愿者";
543 break;
544
545 case 0x0308:
546 strHoliday = "妇女节";
547 break;
548
549 case 0x030C:
550 strHoliday = "植树节";
551 break;
552
553 case 0x0401:
554 strHoliday = "愚人节";
555 break;
556
557 case 0x0501:
558 strHoliday = "劳动节";
559 break;
560
561 case 0x0504:
562 strHoliday = "青年节";
563 break;
564
565 case 0x0601:
566 strHoliday = "儿童节";
567 break;
568
569 case 0x0606:
570 strHoliday = "爱眼日";
571 break;
572
573 case 0x0701:
574 strHoliday = "建党节";
575 break;
576
577 case 0x0707:
578 strHoliday = "抗战日";
579 break;
580
581 case 0x0801:
582 strHoliday = "建军节";
583 break;
584
585 case 0x090A:
586 strHoliday = "教师节";
587 break;
588
589 case 0x0A01:
590 strHoliday = "国庆节";
591 break;
592
593 case 0x0B08:
594 strHoliday = "记者节";
595 break;
596
597 case 0x0B09:
598 strHoliday = "消防日";
599 break;
600
601 case 0x0C18:
602 strHoliday = "平安夜";
603 break;
604
605 case 0x0C19:
606 strHoliday = "圣诞节";
607 break;
608
609 default:
610 break;
611 }
612
613 return strHoliday;
614 }
615
616 // 计算二十四节气
617 QString KLunarCalendarInfo::getSolarTerms(int year, int month, int day)
618 {
619 Q_D(KLunarCalendarInfo);
620 QString strSolarTerms;
621 int dayTemp = 0;
622 int index = (year - 1970) * 12 + month - 1;
623
624 if (day < 15) {
625 dayTemp = 15 - day;
626
627 if ((d->chineseTwentyFourData.at(index) >> 4) == dayTemp) {
628 strSolarTerms = d->listSolarTerm.at(2 * (month - 1));
629 }
630 } else if (day > 15) {
631 dayTemp = day - 15;
632
633 if ((d->chineseTwentyFourData.at(index) & 0x0f) == dayTemp) {
634 strSolarTerms = d->listSolarTerm.at(2 * (month - 1) + 1);
635 }
636 }
637
638 return strSolarTerms;
639 }
640
641 // 计算农历节日(必须传入农历年份月份)
642 QString KLunarCalendarInfo::getLunarFestival(int month, int day)
643 {
644 Q_D(KLunarCalendarInfo);
645 int temp = (month << 8) | day;
646 QString strFestival;
647
648 switch (temp) {
649 case 0x0201:
650 strFestival = "二月";
651 break;
652
653 case 0x0301:
654 strFestival = "三月";
655 break;
656
657 case 0x0401:
658 strFestival = "四月";
659 break;
660
661 case 0x0501:
662 strFestival = "五月";
663 break;
664
665 case 0x0601:
666 strFestival = "六月";
667 break;
668
669 case 0x0701:
670 strFestival = "七月";
671 break;
672
673 case 0x0801:
674 strFestival = "八月";
675 break;
676
677 case 0x0901:
678 strFestival = "九月";
679 break;
680
681 case 0x0A01:
682 strFestival = "十月";
683 break;
684
685 case 0x0B01:
686 strFestival = "冬月";
687 break;
688
689 case 0x0C01:
690 strFestival = "腊月";
691 break;
692
693 case 0x0101:
694 strFestival = "春节";
695 break;
696
697 case 0x010F:
698 strFestival = "元宵节";
699 break;
700
701 case 0x0202:
702 strFestival = "龙抬头";
703 break;
704
705 case 0x0505:
706 strFestival = "端午节";
707 break;
708
709 case 0x0707:
710 strFestival = "七夕节";
711 break;
712
713 case 0x080F:
714 strFestival = "中秋节";
715 break;
716
717 case 0x0909:
718 strFestival = "重阳节";
719 break;
720
721 case 0x0C08:
722 strFestival = "腊八节";
723 break;
724
725 case 0x0C1E:
726 strFestival = "除夕";
727 break;
728
729 default:
730 break;
731 }
732
733 return strFestival;
734 }
735
736 // 计算农历年 天干+地支+生肖
737 QString KLunarCalendarInfo::getLunarYear(int year)
738 {
739 Q_D(KLunarCalendarInfo);
740 QString strYear;
741
742 if (year > 1924) {
743 int temp = year - 1924;
744 strYear.append(d->listTianGan.at(temp % 10));
745 strYear.append(d->listDiZhi.at(temp % 12));
746 strYear.append("年");
747 strYear.append(d->listShuXiang.at(temp % 12));
748 strYear.append("年");
749 }
750
751 return strYear;
752 }
753
754 void KLunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
755 QString &strHoliday,
756 QString &strSolarTerms,
757 QString &strLunarFestival,
758 QString &strLunarYear,
759 QString &strLunarMonth,
760 QString &strLunarDay)
761 {
762
763 Q_D(KLunarCalendarInfo);
764 if (year < 1901 || year > 2099 || month < 1 || month > 12 || day < 1 || day > 31) {
765 return;
766 }
767
768 strHoliday = getHoliday(month, day);
769 strSolarTerms = getSolarTerms(year, month, day);
770
771 #ifndef year_2099
772 // 现在计算农历:获得当年春节的公历日期(比如:2015年春节日期为(2月19日))
773 // 以此为分界点,2.19前面的农历是2014年农历(用2014年农历数据来计算)
774 // 2.19以及之后的日期,农历为2015年农历(用2015年农历数据来计算)
775 int temp, tempYear, tempMonth, isEnd, k, n;
776 tempMonth = year - 1968;
777 int springFestivalMonth = d->springFestival.at(tempMonth) / 100;
778 int springFestivalDaty = d->springFestival.at(tempMonth) % 100;
779
780 if (month < springFestivalMonth) {
781 tempMonth--;
782 tempYear = 365 * 1 + day + d->monthAdd.at(month - 1) - 31 * ((d->springFestival.at(tempMonth) / 100) - 1) - d->springFestival.at(tempMonth) % 100 + 1;
783
784 if ((!(year % 4)) && (month > 2)) {
785 tempYear = tempYear + 1;
786 }
787
788 if ((!((year - 1) % 4))) {
789 tempYear = tempYear + 1;
790 }
791 } else if (month == springFestivalMonth) {
792 if (day < springFestivalDaty) {
793 tempMonth--;
794 tempYear = 365 * 1 + day + d->monthAdd.at(month - 1) - 31 * ((d->springFestival.at(tempMonth) / 100) - 1) - d->springFestival.at(tempMonth) % 100 + 1;
795
796 if ((!(year % 4)) && (month > 2)) {
797 tempYear = tempYear + 1;
798 }
799
800 if ((!((year - 1) % 4))) {
801 tempYear = tempYear + 1;
802 }
803 } else {
804 tempYear = day + d->monthAdd.at(month - 1) - 31 * ((d->springFestival.at(tempMonth) / 100) - 1) - d->springFestival.at(tempMonth) % 100 + 1;
805
806 if ((!(year % 4)) && (month > 2)) {
807 tempYear = tempYear + 1;
808 }
809 }
810 } else {
811 tempYear = day + d->monthAdd.at(month - 1) - 31 * ((d->springFestival.at(tempMonth) / 100) - 1) - d->springFestival.at(tempMonth) % 100 + 1;
812
813 if ((!(year % 4)) && (month > 2)) {
814 tempYear = tempYear + 1;
815 }
816 }
817
818 // 计算农历天干地支月日
819 isEnd = 0;
820
821 while (isEnd != 1) {
822 if (d->lunarData.at(tempMonth) < 4095) {
823 k = 11;
824 } else {
825 k = 12;
826 }
827
828 n = k;
829
830 while (n >= 0) {
831 temp = d->lunarData.at(tempMonth);
832 temp = temp >> n;
833 temp = temp % 2;
834
835 if (tempYear <= (29 + temp)) {
836 isEnd = 1;
837 break;
838 }
839
840 tempYear = tempYear - 29 - temp;
841 n = n - 1;
842 }
843
844 if (isEnd) {
845 break;
846 }
847
848 tempMonth = tempMonth + 1;
849 }
850
851 // 农历的年月日
852 year = 1969 + tempMonth - 1;
853 month = k - n + 1;
854 day = tempYear;
855
856 if (k == 12) {
857 if (month == (d->lunarData.at(tempMonth) / 65536) + 1) {
858 month = 1 - month;
859 } else if (month > (d->lunarData.at(tempMonth) / 65536) + 1) {
860 month = month - 1;
861 }
862 }
863
864 strLunarYear = getLunarYear(year);
865
866 if (month < 1 && (1 == day)) {
867 month = month * -1;
868 strLunarMonth = "闰" + d->listMonthName.at(month);
869 } else {
870 strLunarMonth = d->listMonthName.at(month);
871 }
872
873 strLunarDay = d->listDayName.at(day);
874 strLunarFestival = getLunarFestival(month, day);
875 #else
876 // 记录春节离当年元旦的天数
877 int springOffset = 0;
878 // 记录阳历日离当年元旦的天数
879 int newYearOffset = 0;
880 // 记录大小月的天数 29或30
881 int monthCount = 0;
882
883 if (((d->lunarCalendarTable.at(year - 1901) & 0x0060) >> 5) == 1) {
884 springOffset = (d->lunarCalendarTable.at(year - 1901) & 0x001F) - 1;
885 } else {
886 springOffset = (d->lunarCalendarTable.at(year - 1901) & 0x001F) - 1 + 31;
887 }
888
889 // 如果是不闰年且不是2月份 +1
890 newYearOffset = d->monthAdd.at(month - 1) + day - 1;
891
892 if ((!(year % 4)) && (month > 2)) {
893 newYearOffset++;
894 }
895
896 // 记录从哪个月开始来计算
897 int index = 0;
898 // 用来对闰月的特殊处理
899 int flag = 0;
900
901 // 判断阳历日在春节前还是春节后,计算农历的月/日
902 if (newYearOffset >= springOffset) {
903 newYearOffset -= springOffset;
904 month = 1;
905 index = 1;
906 flag = 0;
907
908 if ((d->lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) {
909 monthCount = 29;
910 } else {
911 monthCount = 30;
912 }
913
914 while (newYearOffset >= monthCount) {
915 newYearOffset -= monthCount;
916 index++;
917
918 if (month == ((d->lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) {
919 flag = ~flag;
920
921 if (flag == 0) {
922 month++;
923 }
924 } else {
925 month++;
926 }
927
928 if ((d->lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) {
929 monthCount = 29;
930 } else {
931 monthCount = 30;
932 }
933 }
934
935 day = newYearOffset + 1;
936 } else {
937 springOffset -= newYearOffset;
938 year--;
939 month = 12;
940 flag = 0;
941
942 if (((d->lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20) == 0) {
943 index = 12;
944 } else {
945 index = 13;
946 }
947
948 if ((d->lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) {
949 monthCount = 29;
950 } else {
951 monthCount = 30;
952 }
953
954 while (springOffset > monthCount) {
955 springOffset -= monthCount;
956 index--;
957
958 if (flag == 0) {
959 month--;
960 }
961
962 if (month == ((d->lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) {
963 flag = ~flag;
964 }
965
966 if ((d->lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) {
967 monthCount = 29;
968 } else {
969 monthCount = 30;
970 }
971 }
972
973 day = monthCount - springOffset + 1;
974 }
975
976 // 计算农历的索引配置
977 int temp = 0;
978 temp |= day;
979 temp |= (month << 6);
980
981 // 转换农历的年月
982 month = (temp & 0x3C0) >> 6;
983 day = temp & 0x3F;
984
985 strLunarYear = getLunarYear(year);
986
987 if ((month == ((d->lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) && (1 == day)) {
988 strLunarMonth = "闰" + d->listMonthName.at(month);
989 } else {
990 strLunarMonth = d->listMonthName.at(month);
991 }
992
993 strLunarDay = d->listDayName.at(day);
994 strLunarFestival = getLunarFestival(month, day);
995 #endif
996 }
997
998 QString KLunarCalendarInfo::getLunarInfo(int year, int month, int day, bool yearInfo, bool monthInfo, bool dayInfo)
999 {
1000 Q_D(KLunarCalendarInfo);
1001 QString strHoliday, strSolarTerms, strLunarFestival, strLunarYear, strLunarMonth, strLunarDay;
1002
1003 KLunarCalendarInfo::Instance()->getLunarCalendarInfo(year, month, day,
1004 strHoliday, strSolarTerms, strLunarFestival,
1005 strLunarYear, strLunarMonth, strLunarDay);
1006
1007 // 农历节日优先,其次农历节气,然后公历节日,最后才是农历月份名称
1008 if (!strLunarFestival.isEmpty()) {
1009 strLunarDay = strLunarFestival;
1010 } else if (!strSolarTerms.isEmpty()) {
1011 strLunarDay = strSolarTerms;
1012 } else if (!strHoliday.isEmpty()) {
1013 strLunarDay = strHoliday;
1014 }
1015
1016 QString info = QString("%1%2%3")
1017 .arg(yearInfo ? strLunarYear + "年" : "")
1018 .arg(monthInfo ? strLunarMonth : "")
1019 .arg(dayInfo ? strLunarDay : "");
1020
1021 return info;
1022 }
1023
1024 QString KLunarCalendarInfo::getLunarYearMonthDay(int year, int month, int day)
1025 {
1026 return getLunarInfo(year, month, day, true, true, true);
1027 }
1028
1029 QString KLunarCalendarInfo::getLunarMonthDay(int year, int month, int day)
1030 {
1031 return getLunarInfo(year, month, day, false, true, true);
1032 }
1033
1034 QString KLunarCalendarInfo::getLunarDay(int year, int month, int day)
1035 {
1036 return getLunarInfo(year, month, day, false, false, true);
1037 }
1038 }
1039
1040 #include "klunarcalendarinfo.moc"
1041 #include "moc_klunarcalendarinfo.cpp"