int main( int argc, char *argv[] ){
/*******************************************************************************
    main function
*******************************************************************************/
    int month, year, daycode;
    int time_systimeyear = 2016, time_systimemonth = 5;
    
    if( argc == 1 ){        
        month = time_systimemonth;
        year = time_systimeyear;
        // printf("Compute the current month...\n");
        daycode = getDaycode(year);
        isLeapYear(year);
        displayCalendar(year, month, daycode);
        /*
            insert code for computing the current month
        */
    }
    else if( argc == 2 ){
        if( strcmp(argv[1], "-m") == 0 ){
            printf("cal missing argument for option -m.\n");
        }
        else if( strcmp(argv[1], "-y") == 0 ){
            month = 0;
            year = time_systimeyear;            
            // printf("Compute the current year...\n");
            daycode = getDaycode(year);
            isLeapYear(year);
            displayCalendar(year, month, daycode);
            /* 
                insert code for computing the current year
            */
        }
        else{
            printf("cal: Invalid argument '%s'\n", argv[1]);
        }
    }
    else if( argc == 3 ){
        if( strcmp(argv[1], "-m") == 0 ){            
            month = isValidMonth(argv[2]);
            if( month ){
                year = time_systimeyear;
                daycode = getDaycode(year);
                isLeapYear(year);
                displayCalendar(year, month, daycode);
                // printf("Compute the month of current year...\n");
                /* 
                    insert code for computing month of current year
                */
            }
            else{
                printf("cal: invalid argument '%s'\n", argv[2]);
            }
        }
        else if( strcmp(argv[1], "-y") == 0 ){
            year = atoi(argv[2]);
            if( year == 0 ) printf("cal: invalid argument '%s'\n", argv[2]);
            else if( year > 9999 || year < 1) printf("cal: year `%d' not in range 1..9999\n", year);            
            else if( year >= 1 && year <= 9999 ){
                month = 0;
                daycode = getDaycode(year);
                isLeapYear(year);
                displayCalendar(year, month, daycode);
                // printf("Compute the year...\n");
                /* 
                    insert code for computing the year
                */
            }
            else{
                printf("cal: invalid argument '%s'\n", argv[2]);
            }
        }
        else{
            printf("cal: invalid argument '%s'\n", argv[1]);
        }
    }
    else{
        printf("cal: invalid number of arguments\n");
    }
}// end of main
예제 #2
0
// 일정관리 앱
void scheduler() {
	// 현재 시간 달력 띄우기
	time_t nowTime = time(NULL);
	struct tm *t;
	t = localtime(&nowTime);

	int leapYear;
	int year = t->tm_year + 1900;
	int month = t->tm_mon + 1;
	int day = t->tm_mday;

	printf("%d년 %d월 %d일\n\n", year, month, day);

	leapYear = getLeapYear(year, month);
	printCalendar(year, leapYear, month, day);


	while (1) {
		int scheduleCount = mScheduleCount;
		printf("년도를 입력하세요 : ");
		scanf("%d", &year);
		// 월 제대로 입력했는지 확인
		while(1) {
			printf("월을 입력하세요 : ");
			scanf("%d", &month);
			if (month >= 1 && month <= 12)
				break;
			else {
				printf("다시 입력해주세요.\n");
			}
		}
	
		//일 제대로 입력했는지 확인
		while(1) {
			printf("일을 입력하세요 : ");
			scanf("%d", &day);
			if (day >= 1 && day <= date[month - 1])
				break;
			else {
				if (month == 2) {
					if(isLeapYear(year))
						if (day == 29)
							break;
				}
				printf("다시 입력해주세요.\n");
			}
		}
		leapYear = getLeapYear(year, month);
		// 캘린더 출력
		printCalendar(year, leapYear, month, day);
		
		// 일정 겹치는지 확인
		int overwrite = 1;
		for (int i = 0; i < scheduleCount; i++) {
			// 겹침
			if (mScheduleYear[i] == year && mScheduleMonth[i] == month && mScheduleDay[i] == day) {
				char answer;
				printf("해당 날짜에 이미 일정이 있습니다. 덮어 씌우시겠습니까? (Y or N)");
				getchar();
				answer = getchar();
				// 덮어씌우기
				if (answer == 'Y' || answer == 'y') {
					scheduleCount = i;
					overwrite = 1;
				}
				// 되돌아가기
				else
					overwrite = 0;
				break;
			}
		}

		// 일정 겹쳐서 되돌아가기
		if (overwrite == 0)
			continue;

		printf("일정을 입력하세요 : ");
		getchar();
		
		// 일정 입력
		fgets(mSchedule[scheduleCount], sizeof(mSchedule[scheduleCount]), stdin);
		
		// fgets는 마지막에 \n도 저장되기에 \n을 제거.
		int length = getLength(mSchedule[scheduleCount]);
		mSchedule[scheduleCount][length - 1] = '\0';

		// 일정 저장
		mScheduleYear[scheduleCount] = year;
		mScheduleMonth[scheduleCount] = month;
		mScheduleDay[scheduleCount] = day;
		mScheduleCount++;

		// 캘린더 출력
		printCalendar(year, leapYear, month, day);
	}
}
예제 #3
0
//--------------------------------------------------------------------------
//  dateToDay
//  Функция вычисляет номер дня в году по его дате.
//  Прототип:
//  int dateToDay( int year, int month, int date )
//  Параметры:
//  year    Год.
//  month   Месяц (0-based).
//  date    Число (0-based).
//  Возвращаемое значение: номер дня в году (0-based).
//--------------------------------------------------------------------------
int dateToDay( int year, int month, int date ) {
	int n = date + months[month];
	if( month>1 && isLeapYear(year) ) n++;
	return n;
}
예제 #4
0
// 'month' is 0-based.
static int maxDayOfMonth(int year, int month)
{
    if (month != 1) // February?
        return daysInMonth[month];
    return isLeapYear(year) ? 29 : 28;
}
예제 #5
0
int DateComponents::maxWeekNumberInYear() const
{
    int day = dayOfWeek(m_year, 0, 1); // January 1.
    return day == Thursday || (day == Wednesday && isLeapYear(m_year)) ? 53 : 52;
}
예제 #6
0
int32_t
GregorianCalendar::yearLength(int32_t year) const
{
    return isLeapYear(year) ? 366 : 365;
}
예제 #7
0
int32_t
GregorianCalendar::yearLength() const
{
    return isLeapYear(internalGet(UCAL_YEAR)) ? 366 : 365;
}
예제 #8
0
int32_t
GregorianCalendar::monthLength(int32_t month, int32_t year) const
{
    return isLeapYear(year) ? kLeapMonthLength[month] : kMonthLength[month];
}
예제 #9
0
int32_t GregorianCalendar::handleGetYearLength(int32_t eyear) const {
    return isLeapYear(eyear) ? 366 : 365;
}
예제 #10
0
static inline int daysInYear(int year)
{
    return 365 + isLeapYear(year);
}
예제 #11
0
void datetime_decodeDate(DateTime date, int* year, int* month, int* day)

//  Input:   date = encoded date/time value
//  Output:  year = 4-digit year
//           month = month of year (1-12)
//           day   = day of month
//  Purpose: decodes DateTime value to year-month-day.

{
    int  D1, D4, D100, D400;
    int  y, m, d, i, k, t;

    D1 = 365;              //365
    D4 = D1 * 4 + 1;       //1461
    D100 = D4 * 25 - 1;    //36524
    D400 = D100 * 4 + 1;   //146097

    t = (int)(floor (date)) + DateDelta;
    if (t <= 0)
    {
        *year = 0;
        *month = 1;
        *day = 1;
    }
    else
    {
        t--;
        y = 1;
        while (t >= D400)
        {
            t -= D400;
            y += 400;
        }
        divMod(t, D100, &i, &d);
        if (i == 4)
        {
            i--;
            d += D100;
        }
        y += i*100;
        divMod(d, D4, &i, &d);
        y += i*4;
        divMod(d, D1, &i, &d);
        if (i == 4)
        {
            i--;
            d += D1;
        }
        y += i;
        k = isLeapYear(y);
        m = 1;
        for (;;)
        {
            i = DaysPerMonth[k][m-1];
            if (d < i) break;
            d -= i;
            m++;
        }
        *year = y;
        *month = m;
        *day = d + 1;
    }
}
예제 #12
0
Date NextDate(const Date &now)
{
	if (now.year < MIN_YEAR || now.year > MAX_YEAR)
		throw std::out_of_range("INVALID DATE");
	if (now.month < 1 || now.month > 12)
		throw std::out_of_range("INVALID DATE");
	if (now.day < 1 || now.day > 31)
		throw std::out_of_range("INVALID DATE");
		
	if (isLeapYear(now.year)) {
		if (now.month == 2) {
			if (now.day > 29)
				throw std::out_of_range("INVALID DATE");
			else if (now.day == 29)
				return Date(now.year, 3, 1);
			else 
				return Date(now.year, 2, now.day + 1);
		}
		else if (isSolarMonth(now.month)) {
			if (now.day == 31)
				if (now.month == 12)
					return Date(now.year + 1, 1, 1);
				else
					return Date(now.year, now.month + 1, 1);
			else
				return Date(now.year, now.month, now.day + 1);
		}
		else { // Lunar month
			if (now.day > 30)
				throw std::out_of_range("INVALID DATE");
			else if (now.day == 30)
				return Date(now.year, now.month + 1, 1);
			else
				return Date(now.year, now.month, now.day + 1);
		}
	}
	else {
		if (now.month == 2) {
			if (now.day > 28)
				throw std::out_of_range("INVALID DATE");
			else if (now.day == 28)
				return Date(now.year, 3, 1);
			else 
				return Date(now.year, 2, now.day + 1);
		}
		else if (isSolarMonth(now.month)) {
			if (now.day == 31)
				if (now.month == 12)
					return Date(now.year + 1, 1, 1);
				else
					return Date(now.year, now.month + 1, 1);
			else
				return Date(now.year, now.month, now.day + 1);
		}
		else { // Lunar month
			if (now.day > 30)
				throw std::out_of_range("INVALID DATE");
			else if (now.day == 30)
				return Date(now.year, now.month + 1, 1);
			else
				return Date(now.year, now.month, now.day + 1);
		}
	}
}