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

Side by Side Diff: filters/datesort.py

Issue 29334171: Issue 3410 - Added date sort / format for press releases (Closed)
Patch Set: Created Jan. 20, 2016, 4:58 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
« no previous file with comments | « no previous file | filters/rndsortbydate.py » ('j') | filters/rndsortbydate.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import datetime, random
2 1
3 def datesort(value, basedate="1970-01-01", column=0): 2 from datetime import datetime
4 base = datetime.datetime.strptime(basedate, "%Y-%m-%d") 3
5 def randdiff(entry): 4 def datesort(collection, inputFormat='%Y-%m-%d', outputFormat='%B %d, %Y'):
6 date = datetime.datetime.strptime(entry[column], "%Y-%m-%d") 5 if inputFormat != outputFormat:
7 diff = (date - base).days 6 for item in collection:
8 return diff * 0.2 + random.randrange(diff) * 0.8 7 item[0] = datetime.strftime(datetime.strptime(item[0], inputFormat), outpu tFormat)
9 return sorted(value, key=randdiff) 8 return sorted(collection, key=lambda date: datetime.strptime(date[0], outputFo rmat))
saroyanm 2016/01/22 11:58:14 The items need to be sorted in descending order
juliandoucette 2016/01/25 16:19:55 Done.
OLDNEW
« no previous file with comments | « no previous file | filters/rndsortbydate.py » ('j') | filters/rndsortbydate.py » ('J')

Powered by Google App Engine
This is Rietveld