// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,t,n,r){var a,i=t.getNullSpan();if(a=n.filter(function(e){return isDateDuration(e)&&!hasTime(e)}),1===a.length)return t.getDetachedSpan(t.getDateDD(a[0]).endIso8601).innerDate();if(a=[],void 0!==e.endDate){for(var D,o,s=0;s<e.endDate.length;s++)for(D=t.getSpan().next(e.endDate[s]);D.exists();){if(o=D.nextDate(),o.contains(r)&&(o=o.nextDate()),o.exists()&&/[\d\uff10-\uff19]{1,2}/.test(""+o)&&!/^[\d\uff10-\uff19]{1,2}:[\d\uff10-\uff19]{2}/.test(""+o)){var c=o.getStart()-D.getEnd();c<144&&a.push({match:o,score:c})}D=D.next(e.endDate[s])}a.length>0?(a.sort(function(e,t){return e.score>t.score?1:e.score<t.score?-1:0}),i=a[0].match):(a=n.filter(function(e){return isDateDuration(e)}),a.length&&(i=t.getDetachedSpan(t.getDateDD(a[0]).endIso8601).innerDate()))}return i}}).call();