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

Unified Diff: filters/humandates.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.
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/randomsortbydate.py » ('j') | filters/randomsortbydate.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/humandates.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/filters/humandates.py
@@ -0,0 +1,8 @@
+
saroyanm 2016/02/01 16:24:54 Detail: No new line needed in the beginning of the
juliandoucette 2016/02/02 16:44:45 Done.
+from datetime import datetime
+
+def humandates(collection, inputFormat='%Y-%m-%d', outputFormat='%B %d, %Y'):
saroyanm 2016/02/01 16:24:54 Not really sure if naming this function as human d
juliandoucette 2016/02/02 16:44:45 I changed it because it did more than sort. In th
+ if inputFormat != outputFormat:
Sebastian Noack 2016/02/01 18:01:22 This check is redundant. No need for premature mic
juliandoucette 2016/02/02 16:44:45 Done.
+ for item in collection:
+ item[0] = datetime.strftime(datetime.strptime(item[0], inputFormat), outputFormat)
Sebastian Noack 2016/02/01 18:01:23 A filter changing it's input in-place is quite une
juliandoucette 2016/02/02 16:44:45 I agree. In the next patch I will manipulate a cop
+ return sorted(collection, reverse=True, key=lambda date: datetime.strptime(date[0], outputFormat))
« no previous file with comments | « no previous file | filters/randomsortbydate.py » ('j') | filters/randomsortbydate.py » ('J')

Powered by Google App Engine
This is Rietveld