Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix time range string description bug & remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurty committed Oct 18, 2016
1 parent 56cac19 commit 45e51d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
8 changes: 1 addition & 7 deletions icekit_events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def zero_datetime(dt, tz=None):
Return the given datetime with hour/minutes/seconds/ms zeroed and the
timezone coerced to the given ``tz`` (or UTC if none is given).
"""
if dt is None:
return None
if tz is None:
tz = get_current_timezone()
return coerce_naive(dt).replace(hour=0, minute=0, second=0, microsecond=0)
Expand All @@ -70,10 +68,6 @@ def default_date_starts():
return djtz.date()


def default_date_ends():
return default_date_starts() + appsettings.DEFAULT_DATE_ENDS_DELTA


def format_naive_ical_dt(date_or_datetime):
"""
Return datetime formatted for use in iCal as a *naive* datetime value to
Expand Down Expand Up @@ -755,7 +749,7 @@ class Meta:

def time_range_string(self):
if self.is_all_day:
if self.duration <= timedelta(days=1):
if self.duration < timedelta(days=1):
return u"""{0}, all day""".format(
datefilter(self.local_start, DATE_FORMAT))
else:
Expand Down
32 changes: 32 additions & 0 deletions icekit_events/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,38 @@ def setUp(self):
rounding=timeutils.ROUND_DOWN)
self.end = self.start + appsettings.DEFAULT_ENDS_DELTA

def test_time_range_string(self):
event = G(SimpleEvent)

timed_occurrence = models.Occurrence.objects.create(
event=event,
start=djtz.datetime(2016,10,1, 9,0),
end=djtz.datetime(2016,10,1, 19,0),
)
self.assertEquals(
'Oct. 1, 2016 9 a.m. - Oct. 1, 2016 7 p.m.',
timed_occurrence.time_range_string())

single_day_all_day_occurrence = models.Occurrence.objects.create(
event=event,
start=djtz.datetime(2016,10,1, 0,0),
end=djtz.datetime(2016,10,1, 0,0),
is_all_day=True,
)
self.assertEquals(
'Oct. 1, 2016, all day',
single_day_all_day_occurrence.time_range_string())

multi_day_all_day_occurrence = models.Occurrence.objects.create(
event=event,
start=djtz.datetime(2016,10,1, 0,0),
end=djtz.datetime(2016,10,2, 0,0),
is_all_day=True,
)
self.assertEquals(
'Oct. 1, 2016 - Oct. 2, 2016, all day',
multi_day_all_day_occurrence.time_range_string())

def test_initial_event_occurrences_automatically_created(self):
event = G(SimpleEvent)
self.assertEqual(event.occurrences.count(), 0)
Expand Down

0 comments on commit 45e51d7

Please sign in to comment.