Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: filters/randomsortbydate.py

Issue 29334171: Issue 3410 - Added date sort / format for press releases (Closed)
Patch Set: Fixed rename, typos, and function names Created Jan. 25, 2016, 4:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 import datetime, random
2 1
saroyanm 2016/02/01 16:24:54 Detail: No new line needed in the beginning of the
Sebastian Noack 2016/02/01 18:01:23 It seems the changes in here (except for the funct
juliandoucette 2016/02/02 16:44:45 Done.
juliandoucette 2016/02/02 16:44:46 Done.
3 def datesort(value, basedate="1970-01-01", column=0): 2 import random
4 base = datetime.datetime.strptime(basedate, "%Y-%m-%d") 3 from datetime import datetime
4
5 def randomsortbydate(value, basedate="1970-01-01", column=0):
6 base = datetime.strptime(basedate, "%Y-%m-%d")
5 def randdiff(entry): 7 def randdiff(entry):
6 date = datetime.datetime.strptime(entry[column], "%Y-%m-%d") 8 date = datetime.strptime(entry[column], "%Y-%m-%d")
7 diff = (date - base).days 9 diff = (date - base).days
8 return diff * 0.2 + random.randrange(diff) * 0.8 10 return diff * 0.2 + random.randrange(diff) * 0.8
9 return sorted(value, key=randdiff) 11 return sorted(value, key=randdiff)
OLDNEW

Powered by Google App Engine
This is Rietveld