[CMF-checkins] SVN: CMF/branches/1.5/C - CalendarTool: If an event
ends at exactly midnight, don't show it
Jens Vagelpohl
jens at dataflake.org
Tue Sep 6 19:56:52 EDT 2005
Log message for revision 38330:
- CalendarTool: If an event ends at exactly midnight, don't show it
in the list of events for the day starting at midnight.
(http://www.zope.org/Collectors/CMF/246)
Changed:
U CMF/branches/1.5/CHANGES.txt
U CMF/branches/1.5/CMFCalendar/CalendarTool.py
U CMF/branches/1.5/CMFCalendar/tests/test_Calendar.py
-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt 2005-09-06 22:20:44 UTC (rev 38329)
+++ CMF/branches/1.5/CHANGES.txt 2005-09-06 23:56:51 UTC (rev 38330)
@@ -1,3 +1,11 @@
+After CMF 1.5.4
+
+ Bug Fixes
+
+ - CalendarTool: If an event ends at exactly midnight, don't show it
+ in the list of events for the day starting at midnight.
+ (http://www.zope.org/Collectors/CMF/246)
+
CMF 1.5.4 (2005/09/04)
Bug Fixes
Modified: CMF/branches/1.5/CMFCalendar/CalendarTool.py
===================================================================
--- CMF/branches/1.5/CMFCalendar/CalendarTool.py 2005-09-06 22:20:44 UTC (rev 38329)
+++ CMF/branches/1.5/CMFCalendar/CalendarTool.py 2005-09-06 23:56:51 UTC (rev 38330)
@@ -175,19 +175,28 @@
else:
eventStartDay = result.start.day()
event['start'] = result.start.Time()
- event['title'] = result.Title or result.id
+
+ event['title'] = result.Title or result.getId
+
if eventStartDay != eventEndDay:
allEventDays = range(eventStartDay, eventEndDay+1)
eventDays[eventStartDay]['eventslist'].append( {'end': None,
- 'start': result.start.Time(), 'title': result.Title} )
+ 'start': result.start.Time(), 'title': event['title']} )
eventDays[eventStartDay]['event'] = 1
+
for eventday in allEventDays[1:-1]:
eventDays[eventday]['eventslist'].append( {'end': None,
- 'start': None, 'title': result.Title} )
+ 'start': None, 'title': event['title']} )
eventDays[eventday]['event'] = 1
- eventDays[eventEndDay]['eventslist'].append( {'end':
- result.end.Time(), 'start': None, 'title': result.Title} )
- eventDays[eventEndDay]['event'] = 1
+
+ if result.end == result.end.earliestTime():
+ last_day = eventDays[allEventDays[-2]]
+ last_days_event = last_day['eventslist'][-1]
+ last_days_event['end'] = (result.end-1).latestTime().Time()
+ else:
+ eventDays[eventEndDay]['eventslist'].append( {'end':
+ result.end.Time(), 'start': None, 'title': event['title']} )
+ eventDays[eventEndDay]['event'] = 1
else:
eventDays[eventStartDay]['eventslist'].append(event)
eventDays[eventStartDay]['event'] = 1
@@ -207,10 +216,15 @@
C) Start before this day AND end after this day"""
catalog = self.portal_catalog
+ day, month, year = ( int(thisDay.day())
+ , int(thisDay.month())
+ , int(thisDay.year())
+ )
- first_date, last_date = self.getBeginAndEndTimes(thisDay.day(), thisDay.month(), thisDay.year())
- #first_date=DateTime(thisDay.Date()+" 00:00:00")
- #last_date=DateTime(thisDay.Date()+" 23:59:59")
+ first_date, last_date = self.getBeginAndEndTimes(day, month, year)
+ zone = first_date.localZone()
+ after_midnight_str = '%d-%02d-%02d 00:01:00 %s' % (year,month,day,zone)
+ after_midnight = DateTime(after_midnight_str)
# Get all events that Start on this day
query = self.portal_catalog(
@@ -223,7 +237,7 @@
query += self.portal_catalog(
portal_type=self.getCalendarTypes(),
review_state=self.getCalendarStates(),
- end={'query': (first_date, last_date),
+ end={'query': (after_midnight, last_date),
'range': 'minmax'} )
# Get all events that Start before this day AND End after this day
@@ -255,8 +269,8 @@
security.declarePublic('getPreviousMonth')
def getPreviousMonth(self, month, year):
- # given any particular year and month, this method will return a datetime object
- # for one month prior
+ # given any particular year and month, this method will return a
+ # datetime object for one month prior
try: month=int(month)
except: raise "Calendar Type Error", month
Modified: CMF/branches/1.5/CMFCalendar/tests/test_Calendar.py
===================================================================
--- CMF/branches/1.5/CMFCalendar/tests/test_Calendar.py 2005-09-06 22:20:44 UTC (rev 38329)
+++ CMF/branches/1.5/CMFCalendar/tests/test_Calendar.py 2005-09-06 23:56:51 UTC (rev 38330)
@@ -556,7 +556,41 @@
self.assertEqual(len(self.Site.portal_calendar.getEventsForThisDay(DateTime('2002/05/01'))), 2)
+ def test_EventEndingMidnight(self):
+ # Events ending exactly at midnight should not be shown for the day
+ # after (see http://www.zope.org/Collectors/CMF/246)
+ cal = self.Site.portal_calendar
+ the_day = DateTime('2002/05/01')
+ day_after = DateTime('2002/05/02')
+ self.Site.invokeFactory( 'Event'
+ , id='party'
+ , start_date=the_day
+ , end_date=day_after
+ )
+ self.Site.portal_workflow.doActionFor(self.Site.party, 'publish')
+
+ # One entry should be present for the day of the event
+ self.assertEqual(len(cal.getEventsForThisDay(the_day)), 1)
+
+ # No entry should be present for the day after
+ self.assertEqual(len(cal.getEventsForThisDay(day_after)), 0)
+
+ # First week of May 2002
+ data = [
+ {'day': 1, 'event': 1, 'eventslist':[{'start': '00:00:00', 'end': '23:59:59', 'title': 'party'}]},
+ {'day': 2, 'event': 0, 'eventslist':[]},
+ {'day': 3, 'event': 0, 'eventslist':[]},
+ {'day': 4, 'event': 0, 'eventslist':[]},
+ {'day': 5, 'event': 0, 'eventslist':[]},
+ {'day': 6, 'event': 0, 'eventslist':[]},
+ {'day': 7, 'event': 0, 'eventslist':[]},
+ ]
+
+ events = self.Site.portal_calendar.catalog_getevents(2002, 5)
+ self.assertEqual([events[e] for e in range(1, 8)], data)
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(CalendarTests),
More information about the CMF-checkins
mailing list