Skip to content
Browse files

Parser: better year parsing on *NIX lists

  • Loading branch information...
1 parent 2353048 commit 5e798b850c70c730df177d10cde48a49fcc5c973 @maximethebault maximethebault committed
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/parser.js
View
29 lib/parser.js
@@ -110,6 +110,35 @@ Parser.parseListEntry = function(line) {
mins = '0' + mins;
info.date = new Date(year + '-' + month + '-' + day + 'T'
+ hour + ':' + mins);
+ // if the date is in the past but not older than 6 months ago, year
+ // isn't displayed and doesn't have to be the current year
+ //
+ // if the date is in the future (less than an hour from now), year
+ // isn't displayed and doesn't have to be the current year (if it's
+ // December 31st 23:30 for instance).
+ // That second case is much more rare than the first and less annoying.
+ // It's impossible to fix without knowing about the server's timezone,
+ // so we just don't do anything about it.
+ //
+ // if we're here with a date 28 hours from now in the future (1 hour +
+ // maximum timezone offset which is 27 hours),
+ // there is a problem : we should be in the second conditional block
+ if(info.date.getTime()-new Date().getTime() > 100800000)
+ info.date = new Date((year-1) + '-' + month + '-' + day + 'T'
+ + hour + ':' + mins);
+
+ // if we're here with a date older than 6 months in the past, there's
+ // a problem as well
+ // maybe local & remote servers aren't on the same timezone (with remote
+ // ahead of local)
+ // For instance, remote is in 2014 while local is still in 2013. In
+ // this case, a date like 01/01/13 02:23 could be detected instead of
+ // 01/01/14 02:23
+ // Our trigger point will be 3600*24*31*6 (since we already use 31
+ // as an upper bound, no need to add the 27 hours timezone offset)
+ if(new Date().getTime()-info.date.getTime() > 16070400000)
+ info.date = new Date((year+1) + '-' + month + '-' + day + 'T'
+ + hour + ':' + mins);
} else if (ret.month2 !== undefined) {
month = parseInt(MONTHS[ret.month2.toLowerCase()], 10);
day = parseInt(ret.date2, 10);

0 comments on commit 5e798b8

Please sign in to comment.
Something went wrong with that request. Please try again.