Skip to content
Snippets Groups Projects
Commit 76b2eaf4 authored by Josh Borrow's avatar Josh Borrow
Browse files

Added a random number of seconds [0, 10000] to each datetime object to ensure...

Added a random number of seconds [0, 10000] to each datetime object to ensure that no two 'talks' have the same date.
parent 2d544b3b
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,9 @@ http://jinja.pocoo.org/docs/2.9/api/#custom-filters
Created 26-09-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
"""
import datetime
import dateutil.parser as dp
from random import randint as rand
def sort_cards(cards):
"""
......@@ -22,8 +24,12 @@ def sort_cards(cards):
A list will be returned where the cards are sorted by date.
"""
# We add a random number of seconds in case we have a number of
# cards on the same date.
dates = [
dp.parse(card["date"]) for card in cards
dp.parse(card["date"]) + datetime.timedelta(rand(0, 10000))
for card in cards
]
_, cards = zip(*sorted(zip(dates, cards)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment