2 Copyright (C) 2011 by Cuong Le <metacuong@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>
19 #include <QtCore/QDateTime>
20 #include "lunarcalendar.h"
22 LunarCalendar::LunarCalendar(QObject *parent) :
25 this->curDayA = QDateTime::currentDateTime().toString("d").toUInt();
26 this->curMonthA = QDateTime::currentDateTime().toString("M").toUInt();
27 this->curYearA = QDateTime::currentDateTime().toString("yyyy").toUInt();
33 QString LunarCalendar::nextDay(){
34 int value = this->curDayA+1;
35 int days = calDays(this->curMonthA,this->curYearA);
39 if (this->curMonthA > 12){
45 return QString::number(value);
48 QString LunarCalendar::prevDay(){
49 int value = this->curDayA-1;
52 if (!this->curMonthA){
56 value = calDays( this->curMonthA,this->curYearA);
59 return QString::number(value);
62 int LunarCalendar::curDay(){
66 int LunarCalendar::curMonth(){
67 return this->curMonthA;
70 int LunarCalendar::curYear(){
71 return this->curYearA;
74 int LunarCalendar::curHour(){
75 return QDateTime::currentDateTime().toString("H").toUInt();
78 int LunarCalendar::curMinute(){
79 return QDateTime::currentDateTime().toString("m").toUInt();
82 void LunarCalendar::reset(int D, int M, int Y){
89 int LunarCalendar::calDays(int Month, int Year){
90 if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
94 bool isLeapYear = (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);