Skip to content

Commit

Permalink
fix for multiple days
Browse files Browse the repository at this point in the history
  • Loading branch information
07joshua03 committed Jan 16, 2024
1 parent 642fbc1 commit 1a38e25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
28 changes: 22 additions & 6 deletions narrowcast_content/upcoming_activities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,28 @@ def organize_events_by_day(events, n):
if event_date not in organized_events:
organized_events[event_date] = []

organized_events[event_date].append({
'summary': event['summary'],
'start': (event['start'].replace(tzinfo=pytz.utc) + event['start'].utcoffset()).isoformat(),
'end': (event['end'].replace(tzinfo=pytz.utc) + event['end'].utcoffset()).isoformat(),
'categories': event['categories'],
})
# Check if it is a multiple day event
if event['end'].date() > event['start'].date() and event['end'].hour >= 6:
# Add event for each day until the end date (excluding events ending before 9:00AM the next day)
current_date = event['start'].date()
while current_date <= event['end'].date():
if current_date.strftime('%Y-%m-%d') not in organized_events:
organized_events[current_date.strftime('%Y-%m-%d')] = []
current_date_str = current_date.strftime('%Y-%m-%d')
organized_events[current_date_str].append({
'summary': event['summary'],
'start': (event['start'].replace(tzinfo=pytz.utc) + event['start'].utcoffset()).isoformat(),
'end': (event['end'].replace(tzinfo=pytz.utc) + event['end'].utcoffset()).isoformat(),
'categories': event['categories'],
})
current_date += timedelta(days=1)
else:
organized_events[event_date].append({
'summary': event['summary'],
'start': (event['start'].replace(tzinfo=pytz.utc) + event['start'].utcoffset()).isoformat(),
'end': (event['end'].replace(tzinfo=pytz.utc) + event['end'].utcoffset()).isoformat(),
'categories': event['categories'],
})

today = datetime.now()

Expand Down
12 changes: 7 additions & 5 deletions narrowcast_content/upcoming_activities/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function makeSchedule() {
// Iterate through each day in the schedule
for (var day in schedule) {
if (schedule.hasOwnProperty(day)) {
let date = moment(day)
let date = moment.utc(day)
// Create a div for the day
var dayDiv = document.createElement('div');
dayDiv.className = 'day';
Expand Down Expand Up @@ -121,10 +121,12 @@ async function makeSchedule() {
var timeDiv = document.createElement('div');
timeDiv.className = 'activity-time';

timeDiv.textContent = activity.start.format("HH:mm");

if (activity.start.isSame(activity.end, "day")) {
timeDiv.textContent += ' - ' + activity.end.format("HH:mm");
if(activity.start.isSame(date, "day")) {
timeDiv.textContent = activity.start.format("HH:mm");

if (activity.start.isSame(activity.end, "day")) {
timeDiv.textContent += ' - ' + activity.end.format("HH:mm");
}
}

// Append activity name and time to the activity div
Expand Down

0 comments on commit 1a38e25

Please sign in to comment.