예제 #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());
    }
}
예제 #2
0
파일: drawtime.cpp 프로젝트: Strongc/szarp
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);
}
예제 #3
0
wxDateTime RoundDateToSpan(wxDateTime date, wxDateSpan span)
{
    wxDateTime::wxDateTime_t day = date.GetDay();
    int month = MonthNum(date.GetMonth());
    wxDateTime::wxDateTime_t year = date.GetYear();

    wxDateTime::wxDateTime_t modDays = Mod(day - 1, span.GetTotalDays());
    wxDateTime::wxDateTime_t modMonths = Mod(month - 1, span.GetMonths());
    wxDateTime::wxDateTime_t modYears = Mod(year, span.GetYears());

    return wxDateTime(day - modDays, MonthFromNum(month - modMonths), year - modYears);
}
예제 #4
0
파일: drawtime.cpp 프로젝트: Strongc/szarp
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);
}