anchor.diff:  	String anchorDate = null;
   
   	long maxWindow = -1;
  -	//long wantTime = wbRequest.getReplayDate().getTime();
   	long wantTime = closestDate.getTime();
  -
  +	
   	Iterator<CaptureSearchResult> itr = cResults.iterator();
   	while (itr.hasNext()) {
   		cur = itr.next();
   		cur.getCaptureDate();
  -		//long curDistance = Math.abs(wantTime - cur.getCaptureDate().getTime());
  -		long curDistance = wantTime - cur.getCaptureDate().getTime();
  -		// == 0 propuskaem
  +		long curDistance = cur.getCaptureDate().getTime()-wantTime;
  +		// == 0 skip
   		if (curDistance > 0) {
   			if ((closestright == null)
   					|| (Math.abs(curDistance) < Math
  
positive.code: 
  	}
  
  	if ((dt.before(f)) || dt.after(now)) {
  		//if ((pdate.before(f))||pdate.after(now)) {
  		response.setHeader("TCN", "list");
  		response.setStatus(406);
  		// response.setHeader("Link","<"+agguri+">;rel=\"aggregation\"");
  		// sb.append("}");
  		// response.setHeader("Alternates",sb.toString());
  	} else {
  		// SimpleDateFormat formatterk = new SimpleDateFormat("yyyyMMddHHmmss");
  
  		// StringBuffer sb = new StringBuffer();
  
  		// List list = new ArrayList();
  		if (closestleft != null) {
  			if (!closestleft.getCaptureDate().equals(f)) {
  				//  sb.append(",");
  				//  sb.append("{\"" +  uriPrefix +formatterk.format(closestleft.getCaptureDate())+"/" +u +"\"  "+qvalue);
  				//  sb.append(" {dt " +"\""+httpformatterl.format(closestleft.getCaptureDate()) +"\" prev} {type " + closestleft.getMimeType() +"}}");
  				sb.append(", <" + uriPrefix + formatterk.format(f)
  						+ "/" + u
  						+ ">;rel=\"prev-memento\"; datetime=\""
  						+ httpformatterl.format(f) + "\"");
  				// list.add(closestleft);
  			}
  		}
  		if (closestright != null) {
  			if (!closestright.getCaptureDate().equals(l)) {
  				//  sb.append(",");
  				// sb.append("{\"" +  uriPrefix +formatterk.format(closestright.getCaptureDate())+"/" +u +"\"  " +qvalue);
  				//sb.append(" {dt " +"\""+httpformatterl.format(closestright.getCaptureDate()) +"\" next} {type " + closestright.getMimeType() +"}}");
  				sb.append(", <" + uriPrefix + formatterk.format(f)
  						+ "/" + u
  						+ ">;rel=\"next-memento\"; datetime=\""
  						+ httpformatterl.format(f) + "\"");
  			}
  
  			// list.add(closestright); 
  		}
  
  		//  Iterator it =  list.iterator();
  		//int count=0; 
  		//while (it.hasNext()) {
  
  		//  count++;
  		//CaptureSearchResult alt = (CaptureSearchResult) it.next();
  
  		// sb.append("{");
  		//sb.append("\"" +  uriPrefix +formatterk.format(alt.getCaptureDate())+"/" +u +"\"  ");
  		//sb.append("{dt " + httpformatterl.format(alt.getCaptureDate()) +"} {type " + alt.getMimeType() +"}");
  
  		//sb.append("}");
  		//if (count!=list.size()) {
  		//  sb.append(",");  }
  
  		//}
  
  		// sb.append("}");
  		String origlink = ", <" + u + ">;rel=\"original\"";
  		String memento = ",<" + replayUrl
  				+ ">;rel=\"memento\";datetime=\""
  				+ httpformatterl.format(closestDate) + "\"";
  		response.setHeader("Link", "<" + agguri
  				+ ">;rel=\"timebundle\"" + origlink + sb.toString()
  				+ memento + timemap); //added timemap
  		// response.setHeader("Alternates",sb.toString());
  		response.setHeader("TCN", "choice");
  		response.setHeader("Location", replayUrl);
  		//  response.setStatus(302,"Found"); //does'not work
  		response.sendError(302, "Found");
  
  	}
  %>
negative.code: <%@ page import="java.util.List"  %>
  <%@ page import="java.util.ArrayList" %>
  <%@ page import="org.archive.wayback.ResultURIConverter" %>
  <%@ page import="java.util.TimeZone" %>
  <%@ page import="java.io.PrintWriter"%>
  <%@ page import="org.archive.wayback.archivalurl.ArchivalUrlResultURIConverter" %>
  <%
     //timegate implementation
     String method = request.getMethod();
     // may be there is better place to put this piece of code?
  	if( !(method.equals("GET")||method.equals("HEAD")) )  {
  		response.setStatus(405);	 
  		response.setHeader("Allow", "GET, HEAD");
  		return;
  	}
  
  	response.setHeader("Vary", "negotiate,accept-datetime");
  	SimpleDateFormat httpformatterl = new SimpleDateFormat(
  			"E, dd MMM yyyy HH:mm:ss z");
  			TimeZone tzo = TimeZone.getTimeZone("GMT");
      httpformatterl.setTimeZone(tzo);
      SimpleDateFormat formatterk = new SimpleDateFormat("yyyyMMddHHmmss");
      formatterk.setTimeZone(tzo);
  	Date now = new Date();
  	UIResults results = UIResults.extractCaptureQuery(request);//nuzno potom perepisat'
  
  	WaybackRequest wbRequest = results.getWbRequest();
  
  	String u = wbRequest.getRequestUrl();
  
  	String dtdate = wbRequest.get("dtconneg");
  
  	CaptureSearchResults cResults = results.getCaptureResults();
  	CaptureSearchResult res = cResults.getClosest(wbRequest, true);
  
  	Date closestDate = res.getCaptureDate();
  
  	String agguri = results.getContextConfig("aggregationPrefix")
  			+ "timebundle/" + u;
  	String timemap = " , <"
  			+ results.getContextConfig("aggregationPrefix")
  			+ "timemap/link/" + u
  			+ ">;rel=\"timemap\"; type=\"text/csv\"";
  	String origlink = ", <" + u + ">;rel=\"original\"";
  	ArchivalUrlResultURIConverter uriconverter = (ArchivalUrlResultURIConverter) results
  			.getURIConverter();
  	String uriPrefix = uriconverter.getReplayURIPrefix();
  	String replayUrl = results.resultToReplayUrl(res);
  
  	StringBuffer sb = new StringBuffer();
  	
      String memento = ",<" + replayUrl
  		+ ">;rel=\"memento\";datetime=\""
  		+ httpformatterl.format(closestDate) + "\"";
  	StringFormatter fmt = results.getWbRequest().getFormatter();
  	Date f = cResults.getFirstResultDate();
  	Date l = cResults.getLastResultDate();
  
  	
  	String mfl = null;
  	if ( (closestDate.equals(f)) && closestDate.equals(l)) {
  
  		mfl =	", <" + uriPrefix + formatterk.format(f) + "/" + u
  			+ ">;rel=\"first-memento memento last-memento\"; datetime=\""
  			+ httpformatterl.format(f) + "\"";
  
  	} else if (closestDate.equals(f)){
  
  		mfl = ", <" + uriPrefix + formatterk.format(f) + "/" + u
  			+ ">;rel=\"first-memento memento\"; datetime=\""
  			+ httpformatterl.format(f) + "\""
  			+ ", <" + uriPrefix + formatterk.format(l) + "/" + u
  			+ ">;rel=\"last-memento\"; datetime=\""
  			+ httpformatterl.format(l) + "\"";		
  	
  	} else if (closestDate.equals(l)) {
  
  		 mfl = ", <" + uriPrefix + formatterk.format(l) + "/" + u
  			+ ">;rel=\"last-memento memento\"; datetime=\""
  			+ httpformatterl.format(l) + "\""
  		 	+ ", <" + uriPrefix + formatterk.format(f) + "/" + u
  			+ ">;rel=\"first-memento\"; datetime=\""
  			+ httpformatterl.format(f) + "\"";
  
  	} else  {
  	
  		mfl = memento
  			+ ", <" + uriPrefix + formatterk.format(l) + "/" + u
  			+ ">;rel=\"last-memento\"; datetime=\""
  			+ httpformatterl.format(l) + "\""
  			+ ", <" + uriPrefix + formatterk.format(f) + "/" + u
  			+ ">;rel=\"first-memento\"; datetime=\""
  			+ httpformatterl.format(f) + "\"";
  	}
  	
  	sb = new StringBuffer(mfl);
  	
  	if (dtdate==null) dtdate="";
  	
  	
  	//special handling date unparsable case
  	if (dtdate.equals("unparsable")) {
  		String fl= null;
  		if (f.equals(l)) {
  			 fl=", <" + uriPrefix + formatterk.format(f) + "/" + u
  						+ ">;rel=\"last-memento first-memento\"; datetime=\""
  						+ httpformatterl.format(f) + "\"";
  			
  		} else {
  			fl = ", <" + uriPrefix + formatterk.format(l) + "/" + u
  			+ ">;rel=\"last-memento\"; datetime=\""
  			+ httpformatterl.format(l) + "\"";
  			fl =fl +", <" + uriPrefix + formatterk.format(f) + "/" + u
  					+ ">;rel=\"first-memento\"; datetime=\""
  					+ httpformatterl.format(f) + "\"";
  		}
  		response.setHeader("TCN", "list");
  		response.setStatus(400);
  		response.setHeader("Link", "<" + agguri
  				+ ">;rel=\"timebundle\"" + origlink + fl
  				+ timemap);
  	
        
  	
  		StringBuffer sberr = new StringBuffer();
  		sberr.append("<html><head><title>400  Bad Request</title></head><body>" );
  		sberr.append("<center><table width='800px'><tr><td><div style='background-color: #e0e0e0; padding: 10px;'><br/>");
  		sberr.append("<center><b>Error: 400</b><center>" );
  		sberr.append("<center><p>Bad Date Request.</p>" );
  		sberr.append("However, we found archived resources available in the following time-range: " );
  		sberr.append("<i><blockquote><ul> " );  
  		
  		sberr.append("<li>Very first available Memento  "+   "  at "+  uriPrefix + formatterk.format(f) + "/" + u +"</BR>\n" );
  		sberr.append("<li>Most recent available Memento "  + "  at " + uriPrefix + formatterk.format(f) + "/" + u +"</BR>\n" );
  			
  		
  		sberr.append("</ul> </blockquote></i>" );
  		sberr.append("<br/></div></td></tr>");
  		sberr.append("</table>");
  		sberr.append("</body></html>");
  		PrintWriter pw = response.getWriter();
   		response.setContentType("text/html");
   		pw.print(sberr.toString());
   		pw.flush();
   		pw.close();
  	    return;
  	} 
  	
            
  	// calculate closest values for alternates
  	CaptureSearchResult closestleft = null;
  	CaptureSearchResult closestright = null;
  	long rclosestDistance = 0;
  