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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filters/rndsortbydate.py » ('j') | filters/rndsortbydate.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/datesort.py
===================================================================
--- a/filters/datesort.py
+++ b/filters/datesort.py
@@ -1,9 +1,8 @@
-import datetime, random
-def datesort(value, basedate="1970-01-01", column=0):
- base = datetime.datetime.strptime(basedate, "%Y-%m-%d")
- def randdiff(entry):
- date = datetime.datetime.strptime(entry[column], "%Y-%m-%d")
- diff = (date - base).days
- return diff * 0.2 + random.randrange(diff) * 0.8
- return sorted(value, key=randdiff)
+from datetime import datetime
+
+def datesort(collection, inputFormat='%Y-%m-%d', outputFormat='%B %d, %Y'):
+ if inputFormat != outputFormat:
+ for item in collection:
+ item[0] = datetime.strftime(datetime.strptime(item[0], inputFormat), outputFormat)
+ return sorted(collection, key=lambda date: datetime.strptime(date[0], outputFormat))
saroyanm 2016/01/22 11:58:14 The items need to be sorted in descending order
juliandoucette 2016/01/25 16:19:55 Done.
« no previous file with comments | « no previous file | filters/rndsortbydate.py » ('j') | filters/rndsortbydate.py » ('J')

Powered by Google App Engine
This is Rietveld