Beispiel #1
0
void DateTimeTestCase::TestTimeArithmetics()
{
    static const wxDateSpan testArithmData[] =
    {
        wxDateSpan::Day(),
        wxDateSpan::Week(),
        wxDateSpan::Month(),
        wxDateSpan::Year(),
    };

    // the test will *not* work with arbitrary date!
    wxDateTime dt(2, wxDateTime::Dec, 1999),
               dt1,
               dt2;

    for ( size_t n = 0; n < WXSIZEOF(testArithmData); n++ )
    {
        const wxDateSpan& span = testArithmData[n];
        dt1 = dt + span;
        dt2 = dt - span;

        CPPUNIT_ASSERT_EQUAL( dt, dt1 - span );
        CPPUNIT_ASSERT_EQUAL( dt, dt2 + span );
        CPPUNIT_ASSERT_EQUAL( dt1, dt2 + 2*span );
        CPPUNIT_ASSERT_EQUAL( span, dt1.DiffAsDateSpan(dt) );
    }

    // More date span arithmetics tests
    wxDateTime dtd1(5, wxDateTime::Jun, 1998);
    wxDateTime dtd2(6, wxDateTime::Aug, 1999);

    // All parts in dtd2 is after dtd1
    CPPUNIT_ASSERT_EQUAL( wxDateSpan(1, 2, 0, 1), dtd2.DiffAsDateSpan(dtd1) );

    // Year and month after, day earlier, so no full month
    // Jul has 31 days, so it's 31 - 5 + 4 = 30, or 4w 2d
    dtd2.Set(4, wxDateTime::Aug, 1999);
    CPPUNIT_ASSERT_EQUAL( wxDateSpan(1, 1, 4, 2), dtd2.DiffAsDateSpan(dtd1) );

    // Year and day after, month earlier, so no full year, but same day diff as
    // first example
    dtd2.Set(6, wxDateTime::May, 1999);
    CPPUNIT_ASSERT_EQUAL( wxDateSpan(0, 11, 0, 1), dtd2.DiffAsDateSpan(dtd1) );

    // Year after, month and day earlier, so no full month and no full year
    // April has 30 days, so it's 30 - 5 + 4 = 29, or 4w 1d
    dtd2.Set(4, wxDateTime::May, 1999);
    CPPUNIT_ASSERT_EQUAL( wxDateSpan(0, 10, 4, 1), dtd2.DiffAsDateSpan(dtd1) );

    // And a reverse. Now we should use days in Jun (again 30 => 4w 1d)
    CPPUNIT_ASSERT_EQUAL( wxDateSpan(0, -10, -4, -1), dtd1.DiffAsDateSpan(dtd2) );
}
Beispiel #2
0
void MainFrame::ShowChanged(wxCommandEvent& event) {
	if (ShowChoice->GetSelection() == SHOW_SPECIFIC) {
		PeriodPanel->Show();
		ViewQuery->Criteria.AllEvents = false;
	} else {
		PeriodPanel->Hide();

		if (ShowChoice->GetSelection() == SHOW_TODAYS || ShowChoice->GetSelection() == SHOW_UPCOMING) {
			CalendarCtrl->SetDate(wxDateTime::Today());
			FromDatePicker->SetValue(wxDateTime::Today());

			if (ShowChoice->GetSelection() == SHOW_TODAYS)
				ToDatePicker->SetValue(wxDateTime::Today());
			else
				ToDatePicker->SetValue(wxDateTime::Today().Add(wxDateSpan(0, 0, 0, 7)));

			ViewQuery->Criteria.AllEvents = false;

			UpdateMonthEvents();
		} else if (ShowChoice->GetSelection() == SHOW_ALL) {
			ViewQuery->Criteria.AllEvents = true;
		}
	}

	UpdateEvents();
}
Beispiel #3
0
void TimeIndex::UpdatePeriods() {

	const PeriodType& p = m_time.GetPeriod();

	switch (p) {
		case PERIOD_T_DECADE :
			m_timeres = wxTimeSpan(0, 0, 0, 0);
			m_dateres = wxDateSpan::Year();
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = wxDateSpan::Year() * (m_number_of_values / TimeIndex::PeriodMult[p]);
			break;
		case PERIOD_T_YEAR :
			m_timeres = wxTimeSpan(0, 0, 0, 0);
			m_dateres = wxDateSpan::Month();
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = wxDateSpan::Month() * (m_number_of_values / TimeIndex::PeriodMult[p]);
			break;
		case PERIOD_T_MONTH :
			m_timeres = wxTimeSpan(0, 0, 0, 0);
			m_dateres = wxDateSpan::Day();
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = m_number_of_values == default_units_count[PERIOD_T_MONTH] ?
					wxDateSpan::Month() : wxDateSpan::Day() * (m_number_of_values / TimeIndex::PeriodMult[p]);
			break;
		case PERIOD_T_WEEK :
			m_timeres = wxTimeSpan(8, 0, 0, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = wxDateSpan::Day() * (m_number_of_values / TimeIndex::PeriodMult[p]);
			break;
		case PERIOD_T_DAY :
			m_timeres = wxTimeSpan(0, 10, 0, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(1, 0, 0, 0) * (m_number_of_values / TimeIndex::PeriodMult[p]);
			m_dateperiod = wxDateSpan(0);
			break;
		case PERIOD_T_30MINUTE :
			m_timeres = wxTimeSpan(0, 0, 10, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 1, 0, 0) * (m_number_of_values / TimeIndex::PeriodMult[p]);
			m_dateperiod = wxDateSpan(0);
			break;
		case PERIOD_T_5MINUTE :
			m_timeres = wxTimeSpan(0, 0, 1, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 10, 0) * (m_number_of_values / TimeIndex::PeriodMult[p]);
			m_dateperiod = wxDateSpan(0);
			break;
		case PERIOD_T_MINUTE :
			m_timeres = wxTimeSpan(0, 0, 0, 500);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 5, 0) * (m_number_of_values / TimeIndex::PeriodMult[p]);
			m_dateperiod = wxDateSpan(0);
			break;
		case PERIOD_T_30SEC:
			m_timeres = wxTimeSpan(0, 0, 0, 100);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 1, 0) * (m_number_of_values / TimeIndex::PeriodMult[p]);
			m_dateperiod = wxDateSpan(0);
			break;
		case PERIOD_T_SEASON :
			m_timeres = wxTimeSpan(24 * 7, 0, 0, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = wxDateSpan::Week() * (m_number_of_values / TimeIndex::PeriodMult[p]);
			break;
		default:
			m_timeres = wxTimeSpan(0, 0, 0, 0);
			m_dateres = wxDateSpan(0);
			m_timeperiod = wxTimeSpan(0, 0, 0, 0);
			m_dateperiod = wxDateSpan(0);
			break;
	}
	
	m_time.AdjustToPeriodStart();
}
Beispiel #4
0
void Timeline::DrawTimeline(const wxRect& rect) {
	const wxSize size = GetClientSize();
	int adj_ypos = rect.y - m_scrollPos;
	const int adj_ybottom = adj_ypos + rect.height;

	// Set the clipping region
	m_mdc.DestroyClippingRegion();
	m_mdc.SetClippingRegion(rect.x, adj_ypos, rect.width, rect.height);

	// Clear the background
	m_mdc.SetBrush(m_bgcolor);
	m_mdc.SetPen(m_bgcolor);
	m_mdc.DrawRectangle(0, adj_ypos, size.x, rect.height);

	// Draw the edge
	m_mdc.SetPen(m_edgecolor);
	m_mdc.DrawLine(size.x-1, adj_ypos, size.x-1, adj_ybottom);

	// Find the first visible day
	wxDateTime date;
	unsigned int next_item = 0;
	int y_pos = 0;
	if (m_items.empty()) {
		date = wxDateTime::Now();
	}
	else {
		// Find the first visible item (or the first below visible area)
		for (unsigned int i = 0; i < m_items.size(); ++i) {
			const int item_ybottom = m_items[i].ypos + m_itemHeight;
			if (item_ybottom > rect.y) {
				next_item = i;
				break;
			}
		}

		date = m_items[next_item].date;
		y_pos = m_items[next_item].ypos;

		if (next_item > 0) {
			if (date.IsSameDate(m_items[next_item-1].date)) {
				// If the first item does not have a visible day (there are items from the
				// same day above it), we have to find the last item on the day
				while (next_item+1 < m_items.size() && date.IsSameDate(m_items[next_item+1].date)) {
					++next_item;
				}

				// Add one day (to get first visible day)
				date += wxTimeSpan::Day();
				y_pos = m_items[next_item].ypos + m_itemHeight;

				++next_item; // first item with visible day (might not exists)
			}
			else {
				// Calculate first visible (non-item) date
				const int distance_to_ytop = m_items[next_item].ypos - rect.y;
				int days_to_ytop = distance_to_ytop / m_itemHeight;
				if (distance_to_ytop > 0 && distance_to_ytop % m_itemHeight) ++days_to_ytop;

				date -= wxDateSpan(0, 0, 0, days_to_ytop);
				y_pos = m_items[next_item].ypos - (days_to_ytop * m_itemHeight);
			}
		}
	}

	adj_ypos = y_pos - m_scrollPos;
	int day_of_month = date.GetDay();

	// Calculate y-pos for start of first month
	int month_ypos = adj_ypos;
	if (m_items.empty()) month_ypos = adj_ypos - ((day_of_month-1) * m_itemHeight);
	else {
		const wxDateTime month_start(1, date.GetMonth(), date.GetYear());
		wxDateTime d = date;
		d.ResetTime();
		int prev_item = next_item-1;

		while (d > month_start) {
			month_ypos -= m_itemHeight;

			// There can be multible items on a single day
			if (prev_item >= 0 && d.IsSameDate(m_items[prev_item].date)) --prev_item;
			while (prev_item >= 0 && d.IsSameDate(m_items[prev_item].date)) {
				month_ypos -= m_itemHeight;
				--prev_item;
			}

			d -= wxTimeSpan::Day();
		}
	}

	// Draw the label for the first month
	// (which may be partially or fully hidden)
	{
		const wxString first_monthyear = date.Format(wxT("%B %Y"));
		int textwidth;
		int textheight;
		m_mdc.SetFont(m_labelFont);
		m_mdc.GetTextExtent(first_monthyear, &textwidth, &textheight);
		const int month_label_ybottom = month_ypos + textwidth + 10;
		if (month_label_ybottom > adj_ypos) {
			m_mdc.DrawRotatedText(first_monthyear, 0, month_label_ybottom, 90);
		}
	}

	// Prepare for day drawing
	int days_in_month = wxDateTime::GetNumberOfDays(date.GetMonth(), date.GetYear());
	m_mdc.SetFont(m_dayFont);
	m_mdc.SetTextForeground(m_numbercolor);
	wxString number;
	const int day_xpos = size.x - 17;

	while (adj_ypos < adj_ybottom) {
		if (day_of_month > days_in_month) {
			// Draw a seperator line
			m_mdc.SetPen(m_edgecolor);
			m_mdc.DrawLine(0, adj_ypos-1, size.x, adj_ypos-1);

			// Draw month/year label for the next month
			wxString monthyear = date.Format(wxT("%B %Y"));
			int textwidth;
			int textheight;
			m_mdc.SetFont(m_labelFont);
			m_mdc.GetTextExtent(monthyear, &textwidth, &textheight);
			m_mdc.DrawRotatedText(monthyear, 0, adj_ypos+textwidth+10, 90);
			m_mdc.SetFont(m_dayFont);

			// Go to next month
			day_of_month = 1;
			days_in_month = wxDateTime::GetNumberOfDays(date.GetMonth(), date.GetYear());
		}

		// Check if we should draw a week seperator
		wxDateTime::WeekDay weekday = date.GetWeekDay();
		if (weekday == wxDateTime::Mon) {
			m_mdc.SetPen(m_edgecolor);
			m_mdc.DrawLine(day_xpos, adj_ypos-1, size.x, adj_ypos-1);
		}

		// Draw the day
		//wxString dayname = wxDateTime::GetWeekDayName(weekday, wxDateTime::Name_Abbr);
		//number.Printf(wxT("%.1s %2d"), dayname, day_of_month);
		number.Printf(wxT("%2d"), day_of_month);
		if (!date.IsWorkDay()) {
			// Draw a darker background to highlight holidays
			m_mdc.SetBrush(m_hlightcolor);
			m_mdc.SetPen(m_hlightcolor);
			m_mdc.DrawRectangle(day_xpos, adj_ypos, (size.x-1)-day_xpos, m_itemHeight);

		}
		m_mdc.DrawText(number, day_xpos, adj_ypos);

		// There can be multible items on a single day
		adj_ypos += m_itemHeight;
		if (next_item < m_items.size() && date.IsSameDate(m_items[next_item].date)) ++next_item;
		while (next_item < m_items.size() && date.IsSameDate(m_items[next_item].date)) {
			if (!date.IsWorkDay()) {
				// Draw a darker background to highlight holidays
				m_mdc.DrawRectangle(day_xpos, adj_ypos, (size.x-1)-day_xpos, m_itemHeight);
			}

			adj_ypos += m_itemHeight;
			++next_item;
		}

		++day_of_month;
		date += wxTimeSpan::Day();
	}
}
ReadingPlanWizardDatesPage::ReadingPlanWizardDatesPage(wxWizard *parent) : wxWizardPageSimple(parent)
{
  wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
  wxBoxSizer *topDatesizer = new wxBoxSizer( wxHORIZONTAL );
  wxBoxSizer *startDatesizer = new wxBoxSizer( wxVERTICAL );
  wxBoxSizer *endDatesizer = new wxBoxSizer( wxVERTICAL );
  wxGridSizer *weekdaysSizer = new wxGridSizer(2,4,2,10);

  m_calStart = new wxCalendarCtrl(this, ID_CalendarCtrlStart ,
                                  wxDateTime(wxDefaultDateTime).SetToCurrent(),
                                  wxDefaultPosition,
                                  wxDefaultSize,
                                  wxCAL_SUNDAY_FIRST |
                                  wxCAL_SHOW_HOLIDAYS |
                                  wxRAISED_BORDER );
  wxDateTime endDate(wxDefaultDateTime);
  endDate.SetToCurrent();
  endDate.Add(wxDateSpan(1,0,0,-1));
  m_calEnd = new wxCalendarCtrl(this, ID_CalendarCtrlEnd,
                                endDate,
                                wxDefaultPosition,
                                wxDefaultSize,
                                wxCAL_SUNDAY_FIRST |
                                wxCAL_SHOW_HOLIDAYS |
                                wxRAISED_BORDER );
//  m_calStart->Hide();
//  m_calEnd->Hide();

  m_strStart = new wxStaticText(this, -1, _("Start Date:"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
  m_strEnd = new wxStaticText(this, -1, _("End Date:"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);

  m_strEnd->SetMinSize(wxSize(m_calEnd->GetSize().GetWidth(), m_strEnd->GetSize().GetHeight()));
  m_strStart->SetMinSize(wxSize(m_calStart->GetSize().GetWidth(), m_strStart->GetSize().GetHeight()));

  startDatesizer->Add(m_strStart, 0);
  startDatesizer->Add(m_calStart, 1, wxEXPAND);
//  startDatesizer->SetSizeHints(this);
//  
  endDatesizer->Add(m_strEnd, 0);
  endDatesizer->Add(m_calEnd, 1, wxEXPAND);
  topDatesizer->Add(startDatesizer, 1, wxEXPAND, 10);
  topDatesizer->Add(15,5);
  topDatesizer->Add(endDatesizer, 1, wxEXPAND, 10);

//  SetSizer( topDatesizer );
//  topDatesizer->SetSizeHints(this);

  
  
  
  m_statBox = new wxStaticBox(this, -1, _("Days of Week"));
  wxStaticBoxSizer* statsizer = new wxStaticBoxSizer(m_statBox, wxHORIZONTAL);
  m_ckSunday = new wxCheckBox(this, ID_CheckCtrlSun, _("Sunday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckSunday->SetValue(true);
  m_ckMonday = new wxCheckBox(this, ID_CheckCtrlMon, _("Monday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckMonday->SetValue(true);
  m_ckTuesday = new wxCheckBox(this, ID_CheckCtrlTue, _("Tuesday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckTuesday->SetValue(true);
  m_ckWednesday = new wxCheckBox(this, ID_CheckCtrlWed, _("Wednesday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckWednesday->SetValue(true);
  m_ckThursday = new wxCheckBox(this, ID_CheckCtrlThu, _("Thursday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckThursday->SetValue(true);
  m_ckFriday = new wxCheckBox(this, ID_CheckCtrlFri, _("Friday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckFriday->SetValue(true);
  m_ckSaturday = new wxCheckBox(this, ID_CheckCtrlSat, _("Saturday"), wxDefaultPosition, wxSize(-1,-1));
  m_ckSaturday->SetValue(true);

  weekdaysSizer->Add(m_ckSunday);
  weekdaysSizer->Add(m_ckMonday);
  weekdaysSizer->Add(m_ckTuesday);
  weekdaysSizer->Add(m_ckWednesday);
  weekdaysSizer->Add(m_ckThursday);
  weekdaysSizer->Add(m_ckFriday);
  weekdaysSizer->Add(m_ckSaturday);
  statsizer->Add(weekdaysSizer);

  m_lblDayTotal = new wxStaticText(this, ID_TextCtrlTotal, _("Total Days:") + wxString(wxT(" 0")),wxDefaultPosition, wxSize(-1,-1));

  m_dateBegin = (RPDate)(&m_calStart->GetDate());
  m_dateEnd = (RPDate)(&m_calEnd->GetDate());
  m_dayFlags = SUNDAY | MONDAY | TUESDAY | WEDNESDAY | THURSDAY | FRIDAY | SATURDAY;
  UpdateDays();
  topsizer->Add(topDatesizer,1);
  topsizer->Add(5,15);
  topsizer->Add(statsizer,0);
  topsizer->Add(5,5);
  topsizer->Add(m_lblDayTotal,0);
  SetSizer( topsizer );
  topsizer->SetSizeHints(this);

}