示例#1
0
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());
}
示例#2
0
		void clock::add_months( CORE_MONTHS start_month, CORE_MONTHS end_month ) {
			CORE_MONTHS this_month = start_month;
			while ( this_month != end_month ) {
				add_month( start_month );
				this_month = (CORE_MONTHS)( this_month + 1 );
				if ( this_month == December ) this_month = January;
			}
		}
示例#3
0
TEST(question1_test5, months_test)
{	
	actual_date.year=2012;
	actual_date.month=12;
	actual_date.day=31;
	add_month(actual_date); //add month
	expected_date.year=2013;
	expected_date.month=1;
	expected_date.day=31;	
	CHECK_DATES(expected_date,actual_date);
}
示例#4
0
文件: date.cpp 项目: jensa/cplusplus
		//returns the current month after the operation
		int Date::add_month (int n) {
			if (n > 0){
				for (int i = 0;i<n;i++)
					add_month();
			} else{
				int en = n*-1;
				for (int i=0;i<en;i++){
					subtract_month ();
				}
			}
			return month ();
		}
示例#5
0
/*
 *  add @n days to date
 */
Date& Date::add_day(int n)
{
    if (n) {
	int   left = n;

	while ( (left + d) > month_days(m, y)) {
	    left -= (month_days(m, y) - d + 1);
	    d = 1;
	    add_month(1);
	}

	if (left)
	    d += left;
	
	cache->valid = false;
    }

    return *this;
}
示例#6
0
int get_day(int day, int month, int year)
{
  day += add_month(month, year);
  return day % 7;
}
示例#7
0
void set_date(void) {
  uint8_t mode = init_set_menu(3);
  uint8_t day, month, year;
    
  day = date_d;
  month = date_m;
  year = date_y;
  while (!check_timeout()) {
    
    if (just_pressed & 0x2) {
      just_pressed = 0;
      screenmutex++;

      if (mode == SET_DATE) {
	DEBUG(putstring("Set date month/day, depending on region"));
	// ok now its selected
	mode = next_mode_setdate[region];
	
      } else if (mode == SET_MONTH) {
	DEBUG(putstring("Set date day/year, depending on region"));
	mode = next_mode_setmonth[region];
      } else if (mode == SET_DAY) {
	DEBUG(putstring("Set date month/year, depending on region"));
	mode = next_mode_setday[region];
      } else {
	// done!
	DEBUG(putstring("done setting date"));
	mode = SET_DATE;
	
	//Update the DS1307 with set date.
	writei2ctime(time_s, time_m, time_h, 0, day, month, year);
	date_y = year;
	date_m = month;
	date_d = day;
	
      }
      //Print the instructions below
      print_monthday_help(mode);
      //Refresh the date.
      print_date(month,day,year,mode);
      screenmutex--;
    }
    if ((just_pressed & 0x4) || (pressed & 0x4)) {
      just_pressed = 0;

      screenmutex++;

      if (mode == SET_MONTH) {
      month++;
      }
      if (mode == SET_DAY) {
	day++;
      }
      if (mode == SET_YEAR) {
	year = (year+1) % 100;
      }
      add_month(&month, &day, year);
      print_date(month,day,year,mode);
      screenmutex--;

      if (pressed & 0x4)
	delay_ms(200);  
    }
  }

}