Esempio n. 1
0
wxString CompDateAxis::GetSpanLabel(wxDateTime date, wxDateSpan span)
{
    int days = span.GetDays();
    int weeks = span.GetWeeks();
    int months = span.GetMonths();
    int years = span.GetYears();

    if (days != 0 && weeks == 0 && months == 0 && years == 0) {
        // days span
        int startDay = date.GetDay();
        int endDay = startDay + days;

        wxDateTime::wxDateTime_t maxDay = wxDateTime::GetNumberOfDays(date.GetMonth(), date.GetYear());
        if (endDay > maxDay) {
            endDay -= maxDay;
        }
        return FormatInterval(startDay, endDay);
    }
    else if (days == 0 && weeks != 0 && months == 0 && years == 0) {
        // weeks span
        int startWeek = date.GetWeekOfMonth();
        int endWeek = startWeek + weeks;

        return FormatInterval(startWeek, endWeek);
    }
    else if (days == 0 && weeks == 0 && months != 0 && years == 0) {
        // monthes span
        int startMonth = MonthNum(date.GetMonth());
        int endMonth = startMonth + months;
        if (endMonth > 12) {
            endMonth = endMonth % 12;
        }

        if (months == 1) {
            return wxDateTime::GetMonthName(MonthFromNum(startMonth));
        }
        else {
            return wxString::Format(wxT("%s-%s"),
                                    wxDateTime::GetMonthName(MonthFromNum(startMonth)).c_str(),
                                    wxDateTime::GetMonthName(MonthFromNum(endMonth)).c_str());
        }
    }
    else if (days == 0 && weeks == 0 && months == 0 && years != 0) {
        // years span
        int startYear = date.GetYear();
        int endYear = startYear + years;

        return FormatInterval(startYear, endYear);
    }
    else {
        // we have unaligned span, so print start-end dates
        wxDateTime endDate = date;
        endDate += span;

        return wxString::Format(wxT("%s-%s"),
                                date.Format(wxT("%d-%m-%y")).c_str(),
                                endDate.Format(wxT("%d-%m-%y")).c_str());
    }
}
Esempio n. 2
0
DTime DTime::operator+(const wxDateSpan& span) const {
	//note - this if is neccessary because result of addition of empty
	//wxDateSpan to 02:00 CET at the daylight saving time boundary 
	//magically becomes 02:00 CEST...
	if (span.GetYears() || span.GetMonths() || span.GetWeeks() || span.GetDays())
		return DTime(m_period, m_time + span);
	else
		return DTime(m_period, m_time);
}
Esempio n. 3
0
DTime DTime::operator-(const wxDateSpan& span) const {
	if (span.GetYears() || span.GetMonths() || span.GetWeeks() || span.GetDays())
		return DTime(m_period, m_time - span);
	else
		return DTime(m_period, m_time);
}