CalendarWidget::CalendarWidget(QWidget *parent) : QWidget(parent) { QDate currentDate = QDate::currentDate(); Ct::Date::PersianDate::GregorianToJalali(currentDate, realCurrent_j_y, realCurrent_j_m, realCurrent_j_d); active_j_y = realCurrent_j_y; active_j_m = realCurrent_j_m; int hUnit = this->width() / 7; int vUnit = this->height() / 7; btnPrevMonth = new QPushButton(this); btnPrevMonth->setIcon(QIcon(":/res/1rightarrow.png")); btnPrevMonth->setToolTip(u("ماه قبل")); btnPrevMonth->setGeometry(this->width() - hUnit / 2, 0, hUnit / 2, vUnit); int iconDimension = qMin(btnPrevMonth->width(), btnPrevMonth->height()) - 4; btnPrevMonth->setIconSize(QSize(iconDimension, iconDimension)); connect(btnPrevMonth, SIGNAL(clicked()), this, SLOT(prevMonth())); btnNextMonth = new QPushButton(this); btnNextMonth->setIcon(QIcon(":/res/1leftarrow.png")); btnNextMonth->setToolTip(u("ماه بعد")); btnNextMonth->setGeometry(0, 0, hUnit / 2, vUnit); btnNextMonth->setIconSize(QSize(iconDimension, iconDimension)); connect(btnNextMonth, SIGNAL(clicked()), this, SLOT(nextMonth())); //a `resizeEvent` is automatically generated which draws the month. }
int main(){ //Remember, 1901 was a Tuesday year, so i=2; i=2; j=0; while(done==0){ if(j==1) {//February has 28 days, and 29 every four years //Check if year is a leap year only if the month is February: //We don't need to check 12 times! if(year%4==0){ leap =1; // Uncomment to print leap years //printf("%d \n",year); } else leap=0; while(day<=28+leap){ if (day==28+leap){ nextMonth(j); break; } else nextDay(i); } } else if((j==3)||(j==5)||(j==8)||(j==10)){ //April,June,Sept and Nov have 30 days while(day<=30){ if (day==30){ nextMonth(j); break; } else nextDay(i); } } else { //if it's any other month, 31 days while(day<=31){ if (day==31){ nextMonth(j); break; } else nextDay(i); } } }//end of while loop printf("\n%d\n\n",score); return 0; }
hdate_struct HDate::addMonths(hdate_struct h, int n) { hdate_struct h1 = h; if(n>0){ for(int i =0; i<n;i++){ h1 = nextMonth(h1); } }else if(n<0){ for(int i =0; i>n;i--){ h1 = previousMonth(h1); } } return h1; }
void myDate::nextDay() { // increment day of week and date of month m_day_of_week++; m_date_of_month++; if ( isEndOfWeek() ) { beginNewWeek(); } if ( isEndOfMonth() ) { nextMonth(); } if ( isEndOfYear() ) { nextYear(); } }
void WCalendar::create() { selectionMode_ = SelectionMode::Single; singleClickSelect_ = false; horizontalHeaderFormat_ = CalendarHeaderFormat::ShortDayNames; firstDayOfWeek_ = 1; WDate currentDay = WDate::currentDate(); currentYear_ = currentDay.year(); currentMonth_ = currentDay.month(); WStringStream text; text << "<table class=\"days ${table-class}\" cellspacing=\"0\" cellpadding=\"0\">" """<tr>" "" "<th class=\"caption\">${nav-prev}</th>" "" "<th class=\"caption\"colspan=\"5\">${month} ${year}</th>" "" "<th class=\"caption\">${nav-next}</th>" """</tr>" """<tr>"; for (int j = 0; j < 7; ++j) text << "<th title=\"${t" << j << "}\" scope=\"col\">${d" << j << "}</th>"; text << "</tr>"; for (int i = 0; i < 6; ++i) { text << "<tr>"; for (int j = 0; j < 7; ++j) text << "<td>${c" << (i * 7 + j) << "}</td>"; text << "</tr>"; } text << "</table>"; std::unique_ptr<WTemplate> t(new WTemplate()); impl_ = t.get(); setImplementation(std::move(t)); impl_->setTemplateText(WString::fromUTF8(text.str()), TextFormat::UnsafeXHTML); impl_->setStyleClass("Wt-cal"); setSelectable(false); std::unique_ptr<WText> prevMonth(new WText(tr("Wt.WCalendar.PrevMonth"))); prevMonth->setStyleClass("Wt-cal-navbutton"); prevMonth->clicked().connect(this, &WCalendar::browseToPreviousMonth); std::unique_ptr<WText> nextMonth(new WText(tr("Wt.WCalendar.NextMonth"))); nextMonth->setStyleClass("Wt-cal-navbutton"); nextMonth->clicked().connect(this, &WCalendar::browseToNextMonth); std::unique_ptr<WComboBox> monthEdit(new WComboBox()); monthEdit_ = monthEdit.get(); monthEdit->setInline(true); for (unsigned i = 0; i < 12; ++i) monthEdit->addItem(WDate::longMonthName(i+1)); monthEdit->activated().connect(this, &WCalendar::monthChanged); monthEdit->setDisabled(!WApplication::instance()->environment().ajax()); std::unique_ptr<WInPlaceEdit> yearEdit(new WInPlaceEdit("")); yearEdit_ = yearEdit.get(); yearEdit->setButtonsEnabled(false); yearEdit->lineEdit()->setTextSize(4); yearEdit->setStyleClass("Wt-cal-year"); yearEdit->valueChanged().connect(this, &WCalendar::yearChanged); impl_->bindWidget("nav-prev", std::move(prevMonth)); impl_->bindWidget("nav-next", std::move(nextMonth)); impl_->bindWidget("month", std::move(monthEdit)); impl_->bindWidget("year", std::move(yearEdit)); setHorizontalHeaderFormat(horizontalHeaderFormat_); setFirstDayOfWeek(firstDayOfWeek_); }