Date& Date:: operator--() { _day--; if (_day == 0) { _month--; _day = GetMonthDay(_month); } if (_month == 0) { _year--; _month += 12; } return *this; }
Date& Date::operator++() { _day++; if (_day > GetMonthDay(_month)) { _day = 1; _month++; } if (_month > 12) { _month = 1; _year++; } return *this; }
main() { int year,month,startDay,days,yes_no;//年,月,该月第一天星期几,该月有多少天,是否是闰年 printf("input the year and month<YYYY-MM>:"); scanf("%d-%d",&year,&month); printf(" %d年-%d月\n",year,month);//打印标题YYYY-MM /*调用函数*/ yes_no=CheckLeap ( year); startDay=GetWeekDay (year,month,yes_no); days=GetMonthDay (year,month,yes_no);//值传递和处理 PrintMonthCalender (startDay,days); system("pause"); return 0; }
Date::Date(int year, int month, int day) :_year(year) , _month(month) , _day(day) { if (_year < 1990) _year = 1990; if (_month<0 || _month>12) _month = 1; if (_day < 0 || (!GetMonthDay(month))) { _day = 1; } /*if (!((_year >= 1990) && (_month >= 1 && _month <= 12) && ((day >= 0) && GetMonthDay(month)))) { _year = 1990; _month = 1; _day = 1; }*/ }
void TextMessageProcessor::ProcessText(mpserver::TextMessage* output_message) { StorageMysqlClient mysql_client; const std::string& openid = m_input_message.fromusername(); mysql_client.AddUserMessageAction(openid, m_input_message.content()); std::string content; if (!ConvertUtf8ToGbk(m_input_message.content(), &content)) content.assign(m_input_message.content()); // swap src/dst. output_message->set_tousername(openid); output_message->set_fromusername(m_input_message.tousername()); output_message->set_createtime(static_cast<uint32_t>(time(NULL))); output_message->set_msgtype("text"); std::string resp_content; int ret = 0; int horoscope_type = GetHoroscopeTypeByText(content); int date_type = GetDateByText(content); if (horoscope_type != HoroscopeType_UnknownHoroscope) { if (content.find("绑定") != std::string::npos) { UpdateUserInfo(openid); std::string head = GetUtf8String(""); horoscope::HoroscopeAttr horoscope_attr; ret = mysql_client.GetHoroscopeAttr(horoscope_type, &horoscope_attr); if (ret == 0) { head.append(horoscope_attr.zh_cn_name()); } resp_content = head; horoscope::UserAttr userattr; ret = mysql_client.GetUserAttr( m_input_message.fromusername(), &userattr); userattr.set_horoscope_type(horoscope_type); std::string month = ""; std::string day = ""; if(GetMonthDay(content, month, day)){ if(!month.empty() && !day.empty()) { if(month[0] == '0') month = month.substr(1); if(day[0] == '0') day = day.substr(1); int nMonth = 0; int nDay = 0; ParseNumber(month.c_str(), &nMonth); ParseNumber(day.c_str(), &nDay); userattr.set_birth_month(nMonth); userattr.set_birth_day(nDay); } } else { userattr.set_birth_month(0); userattr.set_birth_day(0); } //ret = redis_client.MergeUserAttr( // m_input_message.fromusername(), userattr); ret = mysql_client.SetUserAttr( m_input_message.fromusername(), userattr); if (ret == 0) { resp_content.append(GetUtf8String(BIND_SUCCESS_WORDING)); } // 双写到mysql // StorageMysqlClient& mysql_client = StorageMysqlClientSingleton::Instance(); // int mysql_ret = mysql_client.SetUserAttr( // m_input_message.fromusername(), userattr); // LOG(INFO) // << "call StorageMysqlClient.SetUserAttr done. openid " // << openid << " ret " << mysql_ret; } else { std::string mysql_content; if(getMysqlFortuneContent(horoscope_type, date_type, mysql_content)) { resp_content = mysql_content; } } resp_content.append("\n\n"); resp_content.append(GetUtf8String(INPUT_MODIFY_HOROSCOPE_WORDING)); } else { int uer_horoscope_type = HoroscopeType_UnknownHoroscope; horoscope::UserAttr userattr; ret = mysql_client.GetUserAttr( m_input_message.fromusername(), &userattr); if (ret == 0) { uer_horoscope_type = userattr.horoscope_type(); } if (uer_horoscope_type != HoroscopeType_UnknownHoroscope) { //已经绑定过星座 if(date_type != UnknownDate) { std::string mysql_content; if(getMysqlFortuneContent(uer_horoscope_type, date_type, mysql_content)) { resp_content = mysql_content; } else { resp_content = GetUtf8String(INPUT_UNKNOWN); LOG(ERROR) << "user input unknown. [" << content << "]"; } } else { resp_content = GetUtf8String(INPUT_UNKNOWN); LOG(ERROR) << "user input unknown. [" << content << "]"; } } else { resp_content = GetUtf8String(INPUT_HOROSCOPE_WITH_BIND_WORDING); } } std::string user_count = UserCountStatSingleton::Instance( ).GetAndReportUserCount(openid); if (!user_count.empty()) { resp_content.append("\n"); resp_content.append(GetUtf8String(user_count)); } if (resp_content.empty()) { LOG(ERROR) << "never come here. " << m_input_message.ShortDebugString(); resp_content = GetUtf8String(NOT_IMPLEMENT_WORDING); } output_message->set_content(resp_content); }