Beispiel #1
0
def getRangeForDate(schemaTime):
    u"""getRangeForDate(IZSchemaDateTime) -> ZDateRange
    Gets the date range that defines the single day represented by
    the given input.  In other words, this function always returns
    a date range that spans a single day, from midnight AM to
    midnight PM.""" #$NON-NLS-1$
    dt = schemaTime.getDateTime(True)
    startDate = createStartDate(dt.year, dt.month, dt.day)
    endDate = createEndDate(dt.year, dt.month, dt.day)
    return ZDateRange(ZSchemaDateTime(startDate), ZSchemaDateTime(endDate))
Beispiel #2
0
def getContainingMonthDateRange(schemaTime):
    u"""getContainingMonthDateRange() -> ZDateRange
    Gets the date range that defines the 28, 29, 30, or 31 day
    month containing the given date.  For example, if the input
    is Dec 20, 2006, the return value would be the range
    beginning Dec 1, 2006 and ending Dec 31, 2006.""" #$NON-NLS-1$
    dt = schemaTime.getDateTime()
    (_notused, numDaysInMonth) = calendar.monthrange(dt.year, dt.month)
    startDate = createStartDate(dt.year, dt.month, 1)
    endDate = createEndDate(dt.year, dt.month, numDaysInMonth)
    return ZDateRange(ZSchemaDateTime(startDate), ZSchemaDateTime(endDate))
Beispiel #3
0
def getContainingWeekDateRange(schemaTime):
    u"""getContainingWeekDateRange(IZSchemaDateTime) -> ZDateRange
    Gets the date range that defines the 7 day week (from Sunday to
    Saturday) containing the given date.  For example, if the
    input is Wed Nov 22, 2006, the return value would be the range
    beginning Sun Nov 19, 2006 and ending Sat Nov 25, 2006.""" #$NON-NLS-1$
    dt = schemaTime.getDateTime()
    weekDay = calendar.weekday(dt.year, dt.month, dt.day)
    # Note: The calendar module returns 0 for Monday, 6 for Sunday
    startDiffDays = (weekDay + 1) % 7
    # Note: -1 mod 7 == 6
    endDiffDays = (6 - (weekDay + 1)) % 7
    startDelta = datetime.timedelta(days = startDiffDays)
    endDelta = datetime.timedelta(days = endDiffDays)
    startDate = dt - startDelta
    endDate = dt + endDelta
    startDate = createStartDate(startDate.year, startDate.month, startDate.day)
    endDate = createEndDate(endDate.year, endDate.month, endDate.day)
    return ZDateRange(ZSchemaDateTime(startDate), ZSchemaDateTime(endDate))