コード例 #1
0
ファイル: Uppgift 5.c プロジェクト: Granddave/Calendar
/* Main program */
void main()
{
	
	// testar monthName()
	for (int i = 1; i < 13; i++)
	{
		printf("%s \n", monthName(i));
	}
	printf("\n");
	
	// testar isLeapYear()
	for (int i = 2000; i < 2010; i++)
		printf("%d is leap year? %d\n", i, isLeapYear(i));
	printf("\n");

	// testar monthDays()
	for (int i = 2000; i < 2010; i++)
		printf("There are %d days in februari %d\n",monthDays(2, i), i);
	printf("\n");
	printf("There are %d days in december 2015", monthDays(12,2015));
	printf("\n\n");

	// testar firstDayOfMonth() och dayName()
	for (int i = 1; i < 13; i++)
		printf("The first day in %s is %s.\n", monthName(i), dayName(firstDayOfMonth(i, 2015)));

	printf("\n");
	system("pause");
}
コード例 #2
0
ファイル: Date.cpp プロジェクト: cristeab/PersonalProject
void Date::getDMY(unsigned int &d, unsigned int &m, unsigned int &y)
{
	y = baseYear_-1;
	long tmp = daysSinceBaseDate_;
	while((tmp -= yearDays(++y)) >= 0);
	tmp += yearDays(y);
	m = 0;
	while ((tmp -= monthDays(++m, y)) >= 0);
	d = tmp+monthDays(m, y)+1;
}
コード例 #3
0
ファイル: check.c プロジェクト: LinuxTeam-teilar/Giortes
int checkDate(int mera, int minas, int etos)
{
    if (mera > monthDays(minas, etos))
    {
        return 1;
    }
    return 0;
}
コード例 #4
0
ファイル: check.c プロジェクト: LinuxTeam-teilar/Giortes
void checkKiniti(char *kiniti, int *mera, int *minas, char *onoma)
{
    if (kiniti[0] != '*')
    {
        if ((*mera == 11 && *minas == 12) || strcmp(onoma, "ΧΛΟΗ") == 0)
        {
            if (dayOfWeek(*mera, *minas, current_year) != 0)
            {
                *mera = *mera + (7-(dayOfWeek(*mera, *minas, current_year)));
            }
        }
        else
        {
            *mera = easter_day + atoi(kiniti);      /* Flawfinder: ignore */
            *minas = easter_month;
        }
        while (*mera < 0)
        {
            *mera += monthDays(*minas-1, current_year);
            *minas = *minas-1;
        }
        while (*mera > monthDays(*minas, current_year))
        {
            *mera -= monthDays(*minas, current_year);
            *minas = *minas+1;
        }
        if (strcmp(onoma, "ΓΕΩΡΓΙΑ") == 0 || strcmp(onoma, "ΓΕΩΡΓΙΟΣ") == 0)
        {
            if (easter_day < 24 && easter_month < 5)
            {
                *mera = 23;
                *minas = 4;
            }
        }
        if (strcmp(onoma, "ΜΑΡΚΟΣ") == 0)
        {
            if (easter_day < 24 && easter_month < 5)
            {
                *mera = 25;
                *minas = 4;
            }
        }
    }
}
コード例 #5
0
ファイル: Date.cpp プロジェクト: cristeab/PersonalProject
int Date::dmy2dsbd(unsigned int d, unsigned int m, unsigned int y)
{
	if (d < 1 || d > monthDays(m, y) || m < 1 || m > 12 || (y < baseYear_))
	{
		return 0;
	}

	int daysSinceBaseDate = 0;
	unsigned int n;
	for (n = baseYear_; n < y; ++n)
	{
		daysSinceBaseDate += yearDays(n);
	}
	for (n = 1; n < m; ++n)
	{
		daysSinceBaseDate += monthDays(n, y);
	}
	daysSinceBaseDate += d-1;
	return daysSinceBaseDate;
}
コード例 #6
0
ファイル: search.c プロジェクト: LinuxTeam-teilar/Giortes
void find(int flag, int cur_add_day)
{
    FILE *input;

    struct event giorti;
    int max_day, flag1=0;
    int mera, minas, etos;
    int verbose=0;      /* when NOT called by the user (-f parameter) the */
    /* user must not see the results of the search    */

    mera = current_day+cur_add_day;
    minas = current_month;
    etos = current_year;

    if (flag == 0)
    {
        verbose = 1;

#ifndef NO_GUI
        hideMainWindowGUI();
#endif

        do
        {
            flag = 0;
#ifndef NO_GUI
            auto_close_flag = 1;
            getDateForFindGUI(&mera, &minas);
#else
            minas= getDateCLI("month");
            mera = getDateCLI("day");
#endif
            flag = checkDate(mera, minas, current_year);
            if (flag == 1)
            {

#ifndef NO_GUI
                invalidDateMsgGUI();
#else
                fprintf(stderr, _("Please try again.\n"));
#endif

            }
        }
        while (flag == 1);
    }

    while ((max_day=monthDays(minas, etos)) < mera)
    {
        mera-=max_day;
        minas++;
        if (minas > 12)
        {
            minas = 1;
            etos++;
        }
    }

    if (no_database != 'p' && no_database != 'a')
    {
        readFile(personal, mera, minas);
    }

    if (no_database != 'i' && no_database != 'a')
    {
        readFile(internat, mera, minas);
    }

    input = fopen(database, "rb");    /* Flawfinder: ignore */
    if (!input)
    {
        if (flag == 0 && quiet == 1 )
        {
            fprintf(stderr, _("Could not locate database file with name <%s>.\n"), database);
        }
        return;
    }

    flag = 0;

    /* search the database from the beginning till the date we search is bigger*/
    /* than database's readed month+2 (because database is sorted and the max */
    /* celebration which depends on east is 56 days after) */
    while (!feof(input) && flag1==0)
    {
        flag1 = 0;
        fread(&giorti, sizeof(struct event), 1, input);

        /* if a celebration depends an the easter day change it's day/month */
        checkKiniti(giorti.kiniti, &giorti.mera, &giorti.minas, giorti.onoma);

        if (!feof(input))
        {
            if (minas == giorti.minas)
            {
                if (mera == giorti.mera)
                {
                    print(giorti);
                    flag = 1;
                }
            }
            if (minas+2 < giorti.minas)
            {
                flag1 = 1;
            }
        }
    }

    fclose(input);

#ifndef NO_GUI
    insertResultIntoLabelGUI();
    strncpy(label_str, "", labelBUFFER);
#endif

    /* If called with the -f parameter print the "no results" message */
    if (verbose == 1 && flag == 0)
    {
#ifndef NO_GUI
        strncpy(label_str, _("\nSearch returned no results.\n\n"), labelBUFFER);
        insertResultIntoLabelGUI();
#else
        fprintf(stdout, _("\nSearch returned no results.\n\n"));
#endif
    }
}
コード例 #7
0
ファイル: testTime.c プロジェクト: WangDongfang/DfewOS
/**********************************************************************************************************
** Function name:           date
** Descriptions:            display now month calendar with color, like this:
**                          -----------------------------
**                           SUN MON TUE WED THU FRI SAT
**                          -----------------------------
**                                                 1   2
**                             3   4   5   6   7   8   9
**                            10  11  12  13  14  15  16
**                            17  18  19  20  21  22  23
**                            24  25  26  27  28  29  30
**                            31
**                          -----------------------------
** input parameters:        NONE
** output parameters:       NONE
** Returned value:          OK: Always
** Created by:              WangDongfang
** Created Date:            2010-07-02
**---------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**---------------------------------------------------------------------------------------------------------
**********************************************************************************************************/
STATUS C_date (int argc, char **argv)
{
    int iFirstWeekday;
    int iDays;
    int i;
    int set_val;
    NONGLI_DATE nong_date;

    TIME_SOCKET tsTimeSet;
    TIME_SOCKET tsTimeNow;
    tsTimeSet = timeGet();

    /*
     * set time if need
     */
    if (argc >= 2) {
        sscanf (argv[1], "%d", (unsigned int *)&set_val);
        if (set_val != 0) { tsTimeSet.iYear = set_val; }
    }
    if (argc >= 3) {
        sscanf (argv[2], "%d", (unsigned int *)&set_val);
        if (set_val != 0) { tsTimeSet.iMon = set_val; }
    }
    if (argc >= 4) {
        sscanf (argv[3], "%d", (unsigned int *)&set_val);
        if (set_val != 0) { tsTimeSet.iDay = set_val; }
    }
    if (argc >= 5) {
        sscanf (argv[4], "%d", (unsigned int *)&tsTimeSet.iHour);
    }
    if (argc >= 6) {
        sscanf (argv[5], "%d", (unsigned int *)&tsTimeSet.iMin);
    }
    if (argc >= 7) {
        sscanf (argv[6], "%d", (unsigned int *)&tsTimeSet.iSec);
    }

    if (argc >= 2) {
        timeSet (tsTimeSet);
    }

    /* 
     * get now time
     */
    tsTimeNow = timeGet();

    iFirstWeekday = (7 - (tsTimeNow.iDay - 1) % 7 + tsTimeNow.iWday) % 7;

    iDays = monthDays(tsTimeNow.iYear, tsTimeNow.iMon);

    MODE_BEGIN_STRING_DATE
    printf("Date  : %d-%02d-%02d\n"
           "Today : %s\n",
            tsTimeNow.iYear,
            tsTimeNow.iMon,
            tsTimeNow.iDay,
            __GpcWeeks[tsTimeNow.iWday]);

    MODE_BEGIN_FRAME
    printf("-----------------------------\n");
    for (i = 0; i < 7; i++) {                                           /*  SUN MON TUE ... SAT          */
        printf(" %s", __GpcWeeksShort[i]);
    }
    printf("\n");
    printf("-----------------------------\n");
    for (i = 0; i < iFirstWeekday; i++) {                               /*  The Blanks before 1#         */
        printf("    ");
    }
    for (i = 1; i <= iDays; i++) {                                      /*  The days 1# ... 31#          */
        if (iFirstWeekday == 6 || iFirstWeekday == 0) {
            MODE_BEGIN_WEEKEND
        } else {
            MODE_BEGIN_WEEKDAY
        }
        if (i == tsTimeNow.iDay) {
            printf("  ");
            MODE_BEGIN_TODDAY
            printf("%2d", i);
            MODE_END_TODDAY
        } else {
コード例 #8
0
void menuEditMonth(uint8_t flags)
{
	if (flags & INTERFACE_MENU_INITIALIZE)
	{
		s_schoolYearForThisMonth = (uint16_t)controllerSettingsGetPointer()->schoolYear + 1900;
		if (s_editingMonth <= 7) s_schoolYearForThisMonth++;

		s_minDay = 1;
		s_maxDay = monthDays(s_editingMonth + 1, s_schoolYearForThisMonth);
		internalStorageMonthRead(s_editingMonth, &s_month);

		s_currentDay = s_minDay;

		s_multiselectMode = 0;
		s_multiselectCenter = 0;

		interfaceMenuTimerReset(0);
	}

	if (interfaceMenuTimerGet(0) >= MENU_HIGHLIGHT_TOGGLE_TICKS * 2) interfaceMenuTimerReset(0);

	if (menuEditMonthReturningMenuIsVisible())
	{
		menuEditMonthWriteSave();
		menuEditMonthWriteCancel();

		switch(s_currentDay - s_maxDay)
		{
		case MENU_EDITMONTH_SAVE:
			if (menuEditMonthNeedBlink())
				interfaceDisplayWriteChars(MENU_EDITMONTH_SAVE_X, MENU_EDITMONTH_SAVE_Y, ' ', 6);
			break;
		case MENU_EDITMONTH_CANCEL:
			if (menuEditMonthNeedBlink())
				interfaceDisplayWriteChars(MENU_EDITMONTH_CANCEL_X, MENU_EDITMONTH_CANCEL_Y, ' ', 6);
			break;
		}
	}
	else
	{
		uint8_t dayDisplayStart = (s_currentDay - (MENU_EDITMONTH_DISPLAY_DAYS_COUNT / 2) > 1 ? s_currentDay - (MENU_EDITMONTH_DISPLAY_DAYS_COUNT / 2) : 1);
		if (dayDisplayStart > s_maxDay - (MENU_EDITMONTH_DISPLAY_DAYS_COUNT - 1)) dayDisplayStart = s_maxDay - (MENU_EDITMONTH_DISPLAY_DAYS_COUNT - 1);

		for (uint8_t i = 0; i < MENU_EDITMONTH_DISPLAY_DAYS_COUNT; i++)
		{
			uint8_t x = MENU_EDITMONTH_TITLE_X + i * MENU_EDITMONTH_TITLE_OFFSET;
			uint8_t day = dayDisplayStart + i;
			sprintf(menuBuffer, MENU_DAY_FORMAT, day);
			interfaceDisplayWrite(x, MENU_EDITMONTH_TITLE_Y, menuBuffer);

			uint8_t dayOfWeek = computeDayOfWeek(day, s_editingMonth + 1, s_schoolYearForThisMonth);
			if (dayOfWeek == MONDAY)
			{
				interfaceDisplayWriteChar(x - 1, MENU_EDITMONTH_TITLE_Y, MENU_EDITMONTH_WEEK_SEPARATOR_CHAR);
				interfaceDisplayWriteChar(x - 1, MENU_EDITMONTH_PROFILE_Y, MENU_EDITMONTH_WEEK_SEPARATOR_CHAR);
			}
			else if (dayOfWeek == SUNDAY && i == MENU_EDITMONTH_DISPLAY_DAYS_COUNT - 1)
			{
				interfaceDisplayWriteChar(x + 2, MENU_EDITMONTH_TITLE_Y, MENU_EDITMONTH_WEEK_SEPARATOR_CHAR);
				interfaceDisplayWriteChar(x + 2, MENU_EDITMONTH_PROFILE_Y, MENU_EDITMONTH_WEEK_SEPARATOR_CHAR);
			}
		}

		for (uint8_t i = 0; i < MENU_EDITMONTH_DISPLAY_DAYS_COUNT; i++)
		{
			uint8_t x = MENU_EDITMONTH_PROFILE_X + i * MENU_EDITMONTH_PROFILE_OFFSET;
			uint8_t day = dayDisplayStart + i;

			//if (day == s_currentDay && !s_multiselectMode) continue;

			interfaceDisplayWriteChar(x, MENU_EDITMONTH_PROFILE_Y, menuGetProfileChar(s_month.days[day]));
		}

		if (s_multiselectMode)
		{
			if (menuEditMonthNeedBlink())
			{
				uint8_t start = s_multiselectCenter;
				uint8_t end = s_currentDay;
				int8_t len = (int8_t)start - (int8_t)end;
				if (len < 0) len = -len;

				int8_t minPos, maxPos;
				if (end > start)
				{
					maxPos = menuEditMonthGetCurrentX();
					minPos = maxPos - len * MENU_EDITMONTH_PROFILE_OFFSET;
					maxPos++; // + 1 because profile takes two spaces
					if (minPos < 0) minPos = 0;
				}
				else if (start > end)
				{
					minPos = menuEditMonthGetCurrentX();
					maxPos = minPos + len * MENU_EDITMONTH_PROFILE_OFFSET;
					if (maxPos > INTERFACE_DISPLAY_WIDTH) maxPos = INTERFACE_DISPLAY_WIDTH;
				}
				else // start == end
				{
					minPos = maxPos = menuEditMonthGetCurrentX();
				}

				for (uint8_t i = minPos; i <= maxPos; i++) interfaceDisplayWriteChar(i, MENU_EDITMONTH_PROFILE_Y, 0xFF);
			}
		}
		else
		{
			if (menuEditMonthNeedBlink())
				interfaceDisplayWriteChar(menuEditMonthGetCurrentX(), MENU_EDITMONTH_PROFILE_Y, ' ');
		}
	}

	s_returningMenuPreviousVisible = menuEditMonthReturningMenuIsVisible();

	uint8_t up = interfaceHandleButtonPressed(INTERFACE_BUTTON_UP);
	uint8_t down = interfaceHandleButtonPressed(INTERFACE_BUTTON_DOWN);
	if (up && down)
	{
		s_multiselectMode ^= 1; // toggle
		s_multiselectCenter = s_currentDay;
		interfaceButtonsLock();
	}
	else if (interfaceHandleButtonPulse(INTERFACE_BUTTON_SELECT))
	{
		if (menuEditMonthReturningMenuIsVisible())
		{
			switch(s_currentDay - s_maxDay)
			{
			case MENU_EDITMONTH_SAVE:
				controllerMonthUpdate(s_editingMonth, &s_month);
				interfaceMenuPrevious();
				break;
			case MENU_EDITMONTH_CANCEL: interfaceMenuPrevious(); break;
			}
		}
		else
		{
			if (s_multiselectMode)
			{
				uint8_t rangeStart = s_multiselectCenter;
				uint8_t rangeEnd = s_currentDay;

				if (rangeStart > rangeEnd)
				{
					uint8_t tmp = rangeStart;
					rangeStart = rangeEnd;
					rangeEnd = tmp;
				}

				uint8_t rangeProfileCount[PROFILE_COUNT + 1]; // plus 1 because of no profile
				memset(&rangeProfileCount, 0, PROFILE_COUNT + 1);
				uint8_t bestProfile = 0;
				uint8_t oneProfileChoosen = 1;
				for (uint8_t i = rangeStart; i <= rangeEnd; i++)
				{
					uint8_t profile = s_month.days[i];

					uint8_t tabIndex = (profile == 0xFF ? PROFILE_COUNT : profile); // PROFILE_COUNT is the last index

					if (profile == 0xFF) rangeProfileCount[tabIndex]++;
					else rangeProfileCount[tabIndex]++;

					if (rangeProfileCount[tabIndex] > rangeProfileCount[bestProfile == 0xFF ? PROFILE_COUNT : bestProfile])
					{
						bestProfile = profile;
					}

					if (i > rangeStart && s_month.days[i - 1] != profile) oneProfileChoosen = 0;
				}

				uint8_t profileForAll = (oneProfileChoosen ? menuEditMonthComputeNextProfile(s_month.days[rangeStart]) : bestProfile);
				for (uint8_t i = rangeStart; i <= rangeEnd; i++) s_month.days[i] = profileForAll;
			}
			else
			{
				s_month.days[s_currentDay] = menuEditMonthComputeNextProfile(s_month.days[s_currentDay]);
			}
		}
	}
	else if (interfaceHandleButtonPulse(INTERFACE_BUTTON_UP) || up)
	{
		s_currentDay++;
		if (s_multiselectMode && s_currentDay > s_maxDay) s_currentDay = s_maxDay;
		else if (s_currentDay > s_maxDay + MENU_EDITMONTH_COUNT) s_currentDay = s_minDay;
		if (menuEditMonthReturningMenuIsVisible())
		{
			menuEditMonthWriteSave();
			menuEditMonthWriteCancel();
		}
	}
	else if (interfaceHandleButtonPulse(INTERFACE_BUTTON_DOWN) || down)
	{
		s_currentDay--;
		if (s_multiselectMode && s_currentDay < s_minDay) s_currentDay = s_minDay;
		if (s_currentDay <= 0) s_currentDay = s_maxDay + MENU_EDITMONTH_COUNT;
		if (menuEditMonthReturningMenuIsVisible())
		{
			menuEditMonthWriteSave();
			menuEditMonthWriteCancel();
		}
	}
}