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

Unified Diff: filters/rndsortbydate.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
Index: filters/rndsortbydate.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/filters/rndsortbydate.py
@@ -0,0 +1,12 @@
+
saroyanm 2016/01/22 11:58:14 no need to use short form of the words and abbrevi
saroyanm 2016/01/22 11:58:14 please use "hg rename" when renaming the files, so
juliandoucette 2016/01/25 16:19:55 Done.
juliandoucette 2016/01/25 16:19:55 Done.
+import random
+from datetime import datetime
+
+def rndsortbydate(value, basedate="1970-01-01", column=0):
+ base =datetime.strptime(basedate, "%Y-%m-%d")
+ def randdiff(entry):
+ date = 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)
+

Powered by Google App Engine
This is Rietveld