/* * This redisplays the 3 month panels 2 show the correct 3-month * window, centred around the month containing the "current" date. */ static void update_quarter(Calendar *c) { Day *d = (Day *)c->view->day_info; int year_num, month_num; /* previous month */ year_num = year(previousmonth(c->view->date)); month_num = month(previousmonth(c->view->date)); XtVaSetValues(d->month_panels[0], XmNyear, year_num, XmNmonth, month_num, NULL); /* current month */ year_num = year(c->view->date); month_num = month(c->view->date); XtVaSetValues(d->month_panels[1], XmNyear, year_num, XmNmonth, month_num, NULL); /* next month */ year_num = year(nextmonth(c->view->date)); month_num = month(nextmonth(c->view->date)); XtVaSetValues(d->month_panels[2], XmNyear, year_num, XmNmonth, month_num, NULL); }
void Date::add_year (int n) { this->y += n; if(!valid_date(year(), month(), day())) { this->d = days_this_month(); } this->julian_day_number = calc_julian_day_number(year(), month(), day()); }
void Date::add_month (int n) { // Negative if(n < 0) { int tmp = month(); this->m = tmp - abs(n) > 0 ? tmp - abs(n) : 12 - abs(n + tmp) % 12; if(n + tmp <= 0) { this->y -= (1 + floor(abs(n + tmp)/12)); } } else { int months = abs(n) + month(); if(months % 12 != 0) this->m = months % 12; else this->m = 12; if(months > 12 && months % 12 != 0) { this->y += months / 12; } else if (months > 12) { this->y += months / 12 - 1; } } if(!valid_date(year(), month(), day())) { this->d = days_this_month(); } this->julian_day_number = calc_julian_day_number(year(), month(), day()); }
unsigned int Date::days_this_month() const { if(month() == 2 && is_leap_year(year())) { return 29; } static int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; return monthDays[month()-1]; }
void Julian::add_one_month(){ if((day()==31&&month()==7) || (day()==31&&month()==12)){ offset+=31; return; } if(day()==31){ offset+=30; return; } if(day()==30&&month()==1){ offset+=30; return; } if(day()==29&&month()==1){ if(is_leap_year()){ offset+=31; }else{ offset+=30; } return; } offset+=days_this_month(); return; }
static void parse_datesub(char const * str, int *day, int *mon, int *year) { int i; static char const nchrs[] = "0123456789 \t,/-."; if ((i = month(&str)) != -1) { *mon = i; if ((i = a2i(&str)) != 0) *day = i; } else if ((i = a2i(&str)) != 0) { *day = i; while (*str && strchr(nchrs + 10, *str) != NULL) ++str; if ((i = month(&str)) != -1) *mon = i; else if ((i = a2i(&str)) != 0) *mon = i - 1; } else return; while (*str && strchr(nchrs + 10, *str) != NULL) ++str; if (isdigit((unsigned char)*str)) { *year = atoi(str); if (*year > 1900) *year -= 1900; else if (*year < 32) *year += 100; } }
void timeprint(void) { static char * old_month = 0; /* WSS * HACK * This shouldn't be here at all but time is so screwed up */ /* WSS * HACK * I don't know where else I can check for a new month reliably */ if (!old_month) old_month = month(); else { /* WSS * HACK * ptr comparision... works cause they're static */ if (old_month != month() && Player.rank[LEGION] > 0) { bank_account * account; account = bank_index_number(SalaryAccount); if (account) account->balance += SalaryAmount; old_month = month(); } } wclear(Timew); wprintw(Timew,"%d:%d",showhour(),showminute()); if (showminute()==0) waddch(Timew,'0'); wprintw(Timew,hour()>11 ? " PM \n" : " AM \n"); wprintw(Timew,month()); wprintw(Timew," the %d",day()); wprintw(Timew,ordinal(day())); wrefresh(Timew); }
/** * Attempt to parse an HTTP Full Date (3.3.1), returning true on success. */ bool parse_date(const char *s, struct tm *tm) { int r; int len = strlen(s); regmatch_t pmatch[20]; tm->tm_isdst = 0; tm->tm_gmtoff = 0; tm->tm_zone = "GMT"; if (len == 29) { /* RFC 1123 */ r = regexec(&re_rfc1123, s, 20, pmatch, 0); if (r == 0) { tm->tm_mday = atoi(s + pmatch[2].rm_so); tm->tm_mon = month(s + pmatch[3].rm_so); tm->tm_year = atoi(s + pmatch[4].rm_so) - 1900; tm->tm_hour = atoi(s + pmatch[5].rm_so); tm->tm_min = atoi(s + pmatch[6].rm_so); tm->tm_sec = atoi(s + pmatch[7].rm_so); return true; } } else if (len == 24) { /* asctime() format */ r = regexec(&re_asctime, s, 20, pmatch, 0); if (r == 0) { if (s[pmatch[3].rm_so] == ' ') tm->tm_mday = atoi(s + pmatch[3].rm_so + 1); else tm->tm_mday = atoi(s + pmatch[3].rm_so); tm->tm_mon = month(s + pmatch[2].rm_so); tm->tm_year = atoi(s + pmatch[7].rm_so) - 1900; tm->tm_hour = atoi(s + pmatch[4].rm_so); tm->tm_min = atoi(s + pmatch[5].rm_so); tm->tm_sec = atoi(s + pmatch[6].rm_so); lookup("asctime"); return true; } } else { /* RFC 1036 */ r = regexec(&re_rfc1036, s, 20, pmatch, 0); if (r == 0) { tm->tm_mday = atoi(s + pmatch[2].rm_so); tm->tm_mon = month(s + pmatch[3].rm_so); tm->tm_year = 100 + atoi(s + pmatch[4].rm_so); tm->tm_hour = atoi(s + pmatch[5].rm_so); tm->tm_min = atoi(s + pmatch[6].rm_so); tm->tm_sec = atoi(s + pmatch[7].rm_so); lookup("rfc1036"); return true; } } lookup("baddate"); return false; }
int main() { using day = std::chrono::day; using year = std::chrono::year; using years = std::chrono::years; using month = std::chrono::month; using months = std::chrono::months; using year_month_day = std::chrono::year_month_day; { // year_month_day + months ASSERT_NOEXCEPT(std::declval<year_month_day>() + std::declval<months>()); ASSERT_NOEXCEPT(std::declval<months>() + std::declval<year_month_day>()); ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() + std::declval<months>())); ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<months>() + std::declval<year_month_day>())); static_assert(testConstexprMonths(year_month_day{year{1}, month{1}, day{1}}), ""); year_month_day ym{year{1234}, std::chrono::January, day{12}}; for (int i = 0; i <= 10; ++i) // TODO test wrap-around { year_month_day ym1 = ym + months{i}; year_month_day ym2 = months{i} + ym; assert(static_cast<int>(ym1.year()) == 1234); assert(static_cast<int>(ym2.year()) == 1234); assert(ym1.month() == month(1 + i)); assert(ym2.month() == month(1 + i)); assert(ym1.day() == day{12}); assert(ym2.day() == day{12}); assert(ym1 == ym2); } } { // year_month_day + years ASSERT_NOEXCEPT(std::declval<year_month_day>() + std::declval<years>()); ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year_month_day>()); ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() + std::declval<years>())); ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<years>() + std::declval<year_month_day>())); static_assert(testConstexprYears (year_month_day{year{1}, month{1}, day{1}}), ""); year_month_day ym{year{1234}, std::chrono::January, day{12}}; for (int i = 0; i <= 10; ++i) { year_month_day ym1 = ym + years{i}; year_month_day ym2 = years{i} + ym; assert(static_cast<int>(ym1.year()) == i + 1234); assert(static_cast<int>(ym2.year()) == i + 1234); assert(ym1.month() == std::chrono::January); assert(ym2.month() == std::chrono::January); assert(ym1.day() == day{12}); assert(ym2.day() == day{12}); assert(ym1 == ym2); } } }
BOOST_FORCEINLINE Date operator >(month_day md, Date d) { Date res; if (res.set_if_valid_date(year(d),month(md),day(md)) && res > d ) return res; if (res.set_if_valid_date(year(year(d)+1),month(md),day(md)) && res > d ) return res; res=Date(year(year(d)+2),month(md),day(md)); return res; }
int Gregorian::mod_julian_day() const{ int a = (14-month())/12; int y = year() + 4800 - a; int m = month()+(12*a)-3; int JDN = day() + (((153*m)+2)/5) + 365*y + (y/4)-(y/100)+(y/400)-32045; return std::floor(JDN - 2400000.5); }
void ContentStructuredDocument::parseDate(const string& dateStr, QDate& dateBegin, QDate& dateEnd) { dateBegin=QDate(); dateEnd=QDate(); char sep('/'); //uint64_t firstSep,secondSep; portage 32 64 std::string::size_type firstSep,secondSep; try { if ( (firstSep=dateStr.find(sep)) != string::npos ) { if ( (secondSep=dateStr.find(sep,firstSep+1)) != string::npos ) { // suppose day/month/year // from_uk_string only defined in recent versions of boost // dateBegin=boost::gregorian::from_uk_string(dateStr); // dateEnd=boost::gregorian::from_uk_string(dateStr); // current version knows only year/month/day string day(dateStr,0,firstSep); string month(dateStr,firstSep+1,secondSep-firstSep); string year(dateStr,secondSep+1); string newDateStr=year+'/'+month+'/'+day; dateBegin=QDate::fromString(newDateStr.c_str()); dateEnd=QDate::fromString(newDateStr.c_str()); } else { // one separator : suppose month/year // find end of month string month(dateStr,0,firstSep); string year(dateStr,firstSep+1); unsigned short monthNum=atoi(month.c_str()); unsigned short yearNum=atoi(year.c_str()); dateBegin=QDate(yearNum,monthNum,1); dateEnd=dateBegin.addMonths(1).addDays(-1); } } else if (! dateStr.empty()) { // no separator : suppose year unsigned short yearNum=atoi(dateStr.c_str()); dateBegin=QDate(yearNum,01,01); dateEnd=QDate(yearNum,12,31); } } //catch (boost::bad_lexical_cast& e) { catch (std::exception& e) { DRLOGINIT; LWARN << "Warning: " << e.what(); LWARN << "Failed parsing of date [" << dateStr << "]"; // do nothing, keep not_a_date_time as default value } }
std::string Date::to_string () const{ std::stringstream stream; stream << year () << "-"; if(month() < 10) stream << "0"; stream << month () << "-"; if (day () < 10) stream << "0"; stream << day (); return stream.str(); }
QString PartialDate::range(const PartialDate& d) const { if (year() != d.year()) return asShortString() + "-" + d.asShortString(); QString result = numberToString(year()); if (month() != d.month()) return QString("%1.%2-%3").arg(year()).arg(asShortString(Month | Day)) .arg(d.asShortString(Month | Day)); else if (day() != d.day()) return QString("%1.%2.%3-%4").arg(year()).arg(month()) .arg(asShortString(Day)).arg(d.asShortString(Day)); else return asShortString(); }
Middle& Middle::add_year(int n) { if(n == 0) return *this; int sign = -1; if( n > 0) { sign = 1; } if(isLeapYear()) { if(std::abs(n) > 3 && isLeapYear(year() + 4*sign)) { _numeric += (365*4 + 1 )*sign; n -= sign * 4; return add_year(n); }else if((sign > 0 && (month() < 3 && !(month() == 2 && day() == 29 ))) || (sign < 0 && (month() > 2 || (month() == 2 && day() == 29 )))) { _numeric += 366 * sign; n -= sign; return add_year(n); } } else if(isLeapYear(year() + sign) && ((( month() > 2 || (month() == 2 && day() == 29 ))&& sign > 0) || (sign < 0 && (month() < 3 && !(month() == 2 && day() == 29 ))))) { _numeric += 366 * sign; n -= sign; return add_year(n); } _numeric += 365 * sign; n -= sign; return add_year(n); }
/* Negativa! */ Date & Julian::add_year(int y){ if(day()==29&&month()==2){ //börjar på skottdag == 29 if((year()+y)%4==0){ // landar på en skottdag == 29 offset = double_julian_day(year()+y,2,29); return *this; }else{ offset = double_julian_day(year()+y,month(),28); // landar på ej skottår return *this; } }else{ // inte börjat på skottdag offset = double_julian_day(year()+y,month(),day()); return *this; } }
int Date::getMonthDays() const { int curMonth = month(); switch (curMonth) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: //Need to consider a leap year in February return isLeapYear() ? 29 : 28; default: return 0; } }
int KCalendarSystem::daysInMonth( const QDate &date ) const { // Days In Month = jd of first day of next month minus jd of first day of this month // Use setAnyDate() to allow correct calculation in last valid year if ( isValid( date ) ) { QDate firstDayOfThisMonth, firstDayOfNextMonth; int thisYear = year( date ); int thisMonth = month( date ); setDate( firstDayOfThisMonth, thisYear, thisMonth, 1 ); //check if next month falls in next year if ( thisMonth < monthsInYear( date ) ) { setDate( firstDayOfNextMonth, thisYear, thisMonth + 1, 1 ); } else { d->setAnyDate( firstDayOfNextMonth, thisYear + 1, 1, 1 ); } return ( firstDayOfNextMonth.toJulianDay() - firstDayOfThisMonth.toJulianDay() ); } return -1; }
void loop() { char str[256]; snprintf(str, 256, "%04u-%02u-%02uT%02u:%02u:%02u", year(), month(), day(), hour(), minute(), second()); Serial.println(str); delay(5000); }
void date::_copy_members (const date& other) { day (other.day()); month (other.month()); year (other.year()); }
char* MoonPhaseLabel() { int m,d,y; int yy,mm; long K1,K2,K3,J; double V; byte PWMvalue; m = month(); d = day(); y = year(); yy = y-((12-m)/10); mm = m+9; if (mm>=12) mm -= 12; K1 = 365.25*(yy+4712); K2 = 30.6*mm+.5; K3 = int(int((yy/100)+49)*.75)-38; J = K1+K2+d+59-K3; V = (J-2451550.1)/29.530588853; V -= floor(V); if (V<0) V++; if (V<0.0625) return "New Moon"; else if (V<0.1875) return "Waxing Crescent"; else if (V<0.3125) return "First Quarter"; else if (V<0.4375) return "Waxing Gibbous"; else if (V<0.5625) return "Full Moon"; else if (V<0.6875) return "Waning Gibbous"; else if (V<0.8125) return "Last Quarter"; else if (V<0.9375) return "Waning Crescent"; else return "New Moon"; }
void digitalDateDisplay(Print& print) { print.print(day()); print.print("."); print.print(month()); print.print("."); print.print(year()); }
QString Percentile::getMaleHead(QDateTime birthday, double measure) { QString a; a = "Unknown"; if (isweekMinorOf13(birthday.date())) { int nweek = week(birthday.date()); if (maleMapHead13Week == NULL) maleMapHead13Week = new PercentileMap(":/tab_hcfa_boys_p_0_13.txt", this); Interval percentile = maleMapHead13Week->find(nweek, measure); a = intervalString(percentile); }else { int nmonth = month(birthday.date()); if (nmonth >= 0 && nmonth <= 60) { if (maleMapHead5Year == NULL) maleMapHead5Year = new PercentileMap(":/tab_hcfa_boys_p_0_5.txt", this); Interval percentile = maleMapHead5Year->find(nmonth, measure); a = intervalString(percentile); } } return a; }
QString Percentile::getFemaleHeight(QDateTime birthday, double measure) { QString a; a = "Unknown"; if (isweekMinorOf13(birthday.date())) { int nweek = week(birthday.date()); if (femaleMapHeight13Week == NULL) femaleMapHeight13Week = new PercentileMap(":/data/tab_lhfa_girls_p_0_13.txt", this); Interval percentile = femaleMapHeight13Week->find(nweek, measure); a = intervalString(percentile); }else { int nmonth = month(birthday.date()); if (nmonth < 25) { if (femaleMapHeight2Year == NULL) femaleMapHeight2Year = new PercentileMap(":/data/tab_lhfa_girls_p_0_2.txt", this); Interval percentile = femaleMapHeight2Year->find(nmonth, measure); fprintf(stdout, "percentile %d", percentile); fflush(stdout); a = intervalString(percentile); } else if (nmonth >= 25 && nmonth <= 60) { if (femaleMapHeight5Year == NULL) femaleMapHeight5Year = new PercentileMap(":/data/tab_lhfa_girls_p_2_5.txt", this); Interval percentile = femaleMapHeight5Year->find(nmonth, measure); a = intervalString(percentile); } } return a; }
void prepared_statement_t::_bind_date_parameter(size_t index, const ::sqlpp::chrono::day_point* value, bool is_null) { if(_handle->debug) { std::cerr << "ODBC debug: binding date parameter" " at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl; } SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0); SQL_DATE_STRUCT ymd_value = {0}; if(!is_null) { const auto ymd = ::date::year_month_day{*value}; ymd_value.year = static_cast<int>(ymd.year()); ymd_value.month = static_cast<unsigned>(ymd.month()); ymd_value.day = static_cast<unsigned>(ymd.day()); } auto rc = SQLBindParameter(_handle->stmt, index, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_DATE, 10, 0, (SQLPOINTER)&ymd_value, sizeof(SQL_DATE_STRUCT), &indPtr); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT)); } }
/* Still UNTESTED: create Unix like long representing the date/time */ uint32_t RTCCValue::getTimestamp() { int i; uint32_t tseconds; uint32_t yr = year() + 2000 - 1970; // seconds from 1970 till 1 jan 00:00:00 of the given year tseconds= yr*(SECS_PER_DAY * 365); for (i = 0; i < yr; i++) { if (LEAP_YEAR(i)) { tseconds += SECS_PER_DAY; // add extra days for leap years } } // add days for this year, months start from 1 for (i = 1; i < month(); i++) { if ( (i == 2) && LEAP_YEAR(yr)) { tseconds += SECS_PER_DAY * 29; } else { tseconds += SECS_PER_DAY * monthDays[i-1]; //monthDay array starts from 0 } } tseconds+= (day()-1) * SECS_PER_DAY; tseconds+= hours() * SECS_PER_HOUR; tseconds+= minutes() * SECS_PER_MIN; tseconds+= seconds(); return tseconds; }
void digitalClockDisplay() { if (sync) { Serial.println("DCF sync good"); sync = false; } Serial.print(day()); Serial.print('.'); Serial.print(month()); Serial.print('.'); Serial.print(year()); Serial.print(' '); Serial.print(' '); const uint8_t minutes = minute(); const uint8_t hours = hour(); print_2_digits(hours); Serial.print(':'); print_2_digits(minutes); Serial.print(':'); print_2_digits(second()); display_digit(minutes % 10, bit0_pin + 0, 4); display_digit(minutes / 10, bit0_pin + 5, 3); display_digit(hours % 10, bit0_pin + 9, 4); display_digit(hours / 10, bit0_pin + 14, 2); Serial.println(); }
lab2::Gregorian::Gregorian(int y, int m, int d) { unsigned const yc = y; unsigned const mc = m; unsigned const dc = d; if((y == 0 && m <= 2) || y < 0 || y > 3000 || m > 12 || m < 1 || d < 1 || (int)days_in_month(mc, yc) < d || (d == 29 && m == 2 && is_leap_year(y) == 0)) { throw std::invalid_argument("Not a valid date"); } ejd = fjd; while(y >= 400) { y -= 400; ejd += 97 * 366 + 303 * 365; } while(y >= 100) { y -= 100; ejd += 24 * 366 + 76 * 365; } while(y >= 4) { y -= 4; ejd += 366 + 3 * 365; } while(y >= 1) { y --; ejd += 365; } while(m > 1) { ejd += month_lengths[m-2]; m--; } //Correct off-by-a-little problems. add_year(yc-year()); add_month(mc-month()); ejd+=(dc-day()); }
void prepared_statement_t::_bind_date_time_parameter(size_t index, const ::sqlpp::chrono::microsecond_point* value, bool is_null) { if(_handle->debug) { std::cerr << "ODBC debug: binding date_time parameter" " at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl; } SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0); SQL_TIMESTAMP_STRUCT ts_value = {0}; if(!is_null) { const auto dp = ::date::floor<::date::days>(*value); const auto time = date::make_time(*value - dp); const auto ymd = ::date::year_month_day{dp}; ts_value.year = static_cast<int>(ymd.year()); ts_value.month = static_cast<unsigned>(ymd.month()); ts_value.day = static_cast<unsigned>(ymd.day()); ts_value.hour = time.hours().count(); ts_value.minute = time.minutes().count(); ts_value.second = time.seconds().count(); ts_value.fraction = time.subseconds().count(); } auto rc = SQLBindParameter(_handle->stmt, index, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, sizeof(SQL_TIMESTAMP_STRUCT), 0, (SQLPOINTER)&ts_value, sizeof(SQL_DATE_STRUCT), &indPtr); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT)); } }
QString Percentile::getFemaleWeight(QDateTime birthday, double measure) { QString a; a = "Unknown"; qDebug() << "IN getFemaleWeight " << endl; if (isweekMinorOf13(birthday.date())) { int nweek = week(birthday.date()); if (femaleMapWeight13Week == NULL) femaleMapWeight13Week = new PercentileMap(":/data/tab_wfa_girls_p_0_13.txt", this); Interval percentile = femaleMapWeight13Week->find(nweek, measure); a = intervalString(percentile); }else { int nmonth = month(birthday.date()); if (nmonth >= 0 && nmonth <= 60) { if (femaleMapWeight5Year == NULL) femaleMapWeight5Year = new PercentileMap(":/data/tab_wfa_girls_p_0_5.txt", this); Interval percentile = femaleMapWeight5Year->find(nmonth, measure); qDebug() << "PErcemtila " << percentile << endl; a = intervalString(percentile); } } return a; }