Skip to content

Commit

Permalink
Merge pull request #199 from nlnwa/issue51_nhc_start_date
Browse files Browse the repository at this point in the history
Fix for issue #51
  • Loading branch information
johnerikhalse committed Feb 3, 2015
2 parents 89e3721 + db27242 commit e6195c1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 77 deletions.
1 change: 1 addition & 0 deletions src/site/xdoc/release_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<li>Removed CustomUserResourceIndex class, which does not appear to have broad utility. <a href="https://github.com/iipc/openwayback/pull/195">#195</a></li>
<li>Performance information in response header can now be in JSON format. <a href="https://github.com/iipc/openwayback/pull/195">#195</a>, <a href="https://github.com/internetarchive/wayback/issues/69">internetarchive#69</a></li>
<li>FastArchivalUrlReplayParseEventHandler no longer rewrite relative URLs for better replay quality. <a href="https://github.com/iipc/openwayback/pull/195">#195</a></li>
<li>Made start date configurable (defaults to old value of 1996), end date dynamic to current year.<a href="https://github.com/iipc/openwayback/issues/51">#51</a></li>
</ul>
</subsection>
<subsection name="Bug Fixes">
Expand Down
109 changes: 59 additions & 50 deletions wayback-core/src/main/java/org/archive/wayback/util/Timestamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import org.archive.util.ArchiveUtils;
Expand All @@ -39,9 +39,8 @@ public class Timestamp {

private final static String LOWER_TIMESTAMP_LIMIT = "10000000000000";
private final static String UPPER_TIMESTAMP_LIMIT = "29991939295959";
private final static String YEAR_LOWER_LIMIT = "1996";
private final static String YEAR_UPPER_LIMIT =
String.valueOf(Calendar.getInstance(TimeZone.getTimeZone("GMT")).get(Calendar.YEAR));
private final static String YEAR_DEFAULT_LOWER_LIMIT = "1996";
private static String YEAR_LOWER_LIMIT;
private final static String MONTH_LOWER_LIMIT = "01";
private final static String MONTH_UPPER_LIMIT = "12";
private final static String DAY_LOWER_LIMIT = "01";
Expand All @@ -52,37 +51,28 @@ public class Timestamp {
private final static String SECOND_UPPER_LIMIT = "59";
private final static String SECOND_LOWER_LIMIT = "00";

private final static int SSE_1996 = 820454400;
// This variable holds the seconds since Epoch (January 1, 1970 00:00:00 GMT)
// to the start of the selected YEAR_LOWER_LIMIT.
private final static int SSE_YEAR_LOWER_LIMIT;

private final static String[] months = { "Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
private final static String[] months = new String[12];

private final static String DAYS_IN_MONTH[][];
private final static int DIM_START_YEAR = 1972;
private final static int DIM_END_YEAR = 2032;
static {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.clear();
int years = DIM_END_YEAR - DIM_START_YEAR;
DAYS_IN_MONTH = new String[years][12];
for(int y = 0; y < years; y++) {
for(int m = 0; m < 12; m++) {
cal.set(Calendar.YEAR,DIM_START_YEAR + y);
cal.set(Calendar.MONTH,m);
cal.set(Calendar.DAY_OF_MONTH,1);
int calV = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
String maxDayOfMonth = String.valueOf(calV);
if(maxDayOfMonth.length() == 1) {
maxDayOfMonth = "0" + maxDayOfMonth;
}
DAYS_IN_MONTH[y][m] = maxDayOfMonth;
}
}
}
private static String getDaysInMonthBound(int year, int month) {
return DAYS_IN_MONTH[year - DIM_START_YEAR][month];
}

// Set up the starting year.

YEAR_LOWER_LIMIT = System.getProperty("wayback.timestamp.startyear", YEAR_DEFAULT_LOWER_LIMIT);

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.set(Integer.parseInt(YEAR_LOWER_LIMIT), 0, 1, 0, 0, 0);
SSE_YEAR_LOWER_LIMIT = (int)(cal.getTimeInMillis() / 1000);

// Set up the array of shorthanded month names.
Map <String, Integer> month = cal.getDisplayNames(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
for (String s:month.keySet()) {
months[month.get(s)] = s;
}
}

private String dateStr = null;
private Date date = null;

Expand Down Expand Up @@ -123,7 +113,7 @@ public Timestamp(final Date date) {
* set internal structure using Date argument
* @param date from which date should be set
*/
public void setDate(final Date date) {
public final void setDate(final Date date) {
this.date = (Date) date.clone();
dateStr = ArchiveUtils.get14DigitDate(date);
}
Expand All @@ -140,7 +130,7 @@ public Date getDate() {
* set internal structure using seconds since the epoch integer argument
* @param sse SecondsSinceEpoch
*/
public void setSse(final int sse) {
public final void setSse(final int sse) {
setDate(new Date(((long)sse) * 1000));
}

Expand Down Expand Up @@ -257,17 +247,13 @@ public String prettyDateTime() {
* =============================
*
*/


private static Calendar getCalendar() {
String[] ids = TimeZone.getAvailableIDs(0);
if (ids.length < 1) {
return null;
}
TimeZone gmt = new SimpleTimeZone(0, ids[0]);
return new GregorianCalendar(gmt);
private static String getDaysInMonthBound(int year, int month) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
return new Integer(cal.getActualMaximum(Calendar.DAY_OF_MONTH)).toString();
}

/**
* @param dateStr up to 14 digit String representing date
* @return a GMT Calendar object, set to the date represented
Expand All @@ -293,6 +279,7 @@ public static Calendar dateStrToCalendar(final String dateStr) {

return cal;
}

/**
* cleanup the dateStr argument assuming earliest values, and return a
* GMT calendar set to the time described by the dateStr.
Expand All @@ -309,10 +296,9 @@ public static Date dateStrToDate(final String dateStr) {
e.printStackTrace();
// TODO: This is certainly not the right thing, but padStartDateStr
// should ensure we *never* get here..
return new Date(SSE_1996);
return new Date((long)SSE_YEAR_LOWER_LIMIT * 1000);
}
}


private static String padDigits(String input, String min, String max,
String missing) {
Expand Down Expand Up @@ -361,7 +347,8 @@ private static String boundTimestamp(String input) {
}
// MAKE SURE THE YEAR IS WITHIN LEGAL BOUNDARIES:
boundTimestamp.append(boundDigits(input.substring(0,4),
YEAR_LOWER_LIMIT,YEAR_UPPER_LIMIT));
YEAR_LOWER_LIMIT,
String.valueOf(Calendar.getInstance(TimeZone.getTimeZone("GMT")).get(Calendar.YEAR) )));

// MAKE SURE THE MONTH IS WITHIN LEGAL BOUNDARIES:
boundTimestamp.append(boundDigits(input.substring(4,6),
Expand Down Expand Up @@ -458,6 +445,28 @@ public static Timestamp latestTimestamp() {
* @return Timestamp object representing the earliest possible date.
*/
public static Timestamp earliestTimestamp() {
return new Timestamp(SSE_1996);
}
return new Timestamp(SSE_YEAR_LOWER_LIMIT);
}

/**
* Set the mimimum year for the service.
* @param year The four digit year to set the lower limit of years handled by the server.
*/
public void setStartYear(int year) {
YEAR_LOWER_LIMIT = Integer.toString(year);
}

/**
* @return The four digit start year of the interval.
*/
public static int getStartYear() {
return Integer.parseInt(YEAR_LOWER_LIMIT);
}

/**
* @return The four digit end year of the interval.
*/
public static int getEndYear() {
return Calendar.getInstance(TimeZone.getTimeZone("GMT")).get(Calendar.YEAR);
}
}
16 changes: 9 additions & 7 deletions wayback-webapp/src/main/webapp/WEB-INF/query/BubbleCalendar.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<%@ page import="org.archive.wayback.core.UIResults" %>
<%@ page import="org.archive.wayback.core.WaybackRequest" %>
<%@ page import="org.archive.wayback.partition.BubbleCalendarData" %>
<%@ page import="org.archive.wayback.util.Timestamp" %>
<%@ page import="org.archive.wayback.util.partition.Partition" %>
<%@ page import="org.archive.wayback.util.StringFormatter" %>
<jsp:include page="/WEB-INF/template/CookieJS.jsp" flush="true" />
Expand All @@ -37,8 +38,9 @@ int imgWidth = 0;
int imgHeight = 75;
int yearWidth = 49;
int monthWidth = 5;
int startYear = Timestamp.getStartYear();
for (int year = 1996; year <= Calendar.getInstance().get(Calendar.YEAR); year++)
for (int year = startYear; year <= Calendar.getInstance().get(Calendar.YEAR); year++)
imgWidth += yearWidth;
BubbleCalendarData data = new BubbleCalendarData(results);
Expand Down Expand Up @@ -67,11 +69,11 @@ var lastDate = <%= data.dataEndMSSE %>;
var wbPrefix = "<%= replayPrefix %>";
var wbCurrentUrl = "<%= data.searchUrlForJS %>";
var curYear = <%= data.yearNum - 1996 %>;
var curYear = <%= data.yearNum - startYear %>;
var curMonth = -1;
var yearCount = 15;
var firstYear = 1996;
var startYear = <%= data.yearNum - 1996 %>;
var firstYear = <%= startYear %>;
var startYear = <%= data.yearNum - startYear %>;
var imgWidth = <%= imgWidth %>;
var yearImgWidth = <%= yearWidth %>;
var monthImgWidth = <%= monthWidth %>;
Expand Down Expand Up @@ -260,7 +262,7 @@ $().ready(function(){
</div>
</a>
<%
for(int i = 1996; i <= Calendar.getInstance().get(Calendar.YEAR); i++) {
for(int i = startYear; i <= Calendar.getInstance().get(Calendar.YEAR); i++) {
String curClass = "inactiveHighlight";
if(data.yearNum == i) {
curClass = "activeHighlight";
Expand All @@ -269,8 +271,8 @@ $().ready(function(){
<div class="wbChartThisContainer">
<a style="text-decoration: none;" href="<%= queryPrefix + i + "0201000000*/" + data.searchUrlForHTML %>">

<div id="highlight-<%= i - 1996 %>"
onmouseover="showTrackers('inline'); setActiveYear(<%= i - 1996 %>)"
<div id="highlight-<%= i - startYear %>"
onmouseover="showTrackers('inline'); setActiveYear(<%= i - startYear %>)"
class="<%= curClass %>"><%= i %></div>
</a>
</div>
Expand Down
9 changes: 5 additions & 4 deletions wayback-webapp/src/main/webapp/WEB-INF/replay/Toolbar.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
%><%@ page import="org.archive.wayback.partition.PartitionPartitionMap"
%><%@ page import="org.archive.wayback.partition.PartitionsToGraph"
%><%@ page import="org.archive.wayback.partition.ToolBarData"
%><%@ page import="org.archive.wayback.util.Timestamp"
%><%@ page import="org.archive.wayback.util.graph.Graph"
%><%@ page import="org.archive.wayback.util.graph.GraphEncoder"
%><%@ page import="org.archive.wayback.util.graph.GraphRenderer"
Expand Down Expand Up @@ -51,8 +52,9 @@ int imgWidth = 0;
int imgHeight = 27;
int monthWidth = 2;
int yearWidth = 25;
int startYear = Timestamp.getStartYear();
for (int year = 1996; year <= Calendar.getInstance().get(Calendar.YEAR); year++)
for (int year = startYear; year <= Calendar.getInstance().get(Calendar.YEAR); year++)
imgWidth += yearWidth;
String yearFormatKey = "PartitionSize.dateHeader.yearGraphLabel";
Expand All @@ -77,7 +79,7 @@ var wbCurrentUrl = "<%= searchUrlJS %>";
var curYear = -1;
var curMonth = -1;
var yearCount = 15;
var firstYear = 1996;
var firstYear = <%= startYear %>;
var imgWidth=<%= imgWidth %>;
var yearImgWidth = <%= yearWidth %>;
var monthImgWidth = <%= monthWidth %>;
Expand Down Expand Up @@ -129,7 +131,6 @@ function trackMouseMove(event,element) {
var monthOff = xOff % yearImgWidth;
var year = Math.floor(xOff / yearImgWidth);
var yearStart = year * yearImgWidth;
var monthOfYear = Math.floor(monthOff / monthImgWidth);
if(monthOfYear > 11) {
monthOfYear = 11;
Expand All @@ -146,7 +147,7 @@ function trackMouseMove(event,element) {
zeroPad(day,2) + "000000";
var monthString = prettyMonths[monthOfYear];
document.getElementById("displayYearEl").innerHTML = year + 1996;
document.getElementById("displayYearEl").innerHTML = year + <%= startYear %>;
document.getElementById("displayMonthEl").innerHTML = monthString;
// looks too jarring when it changes..
//document.getElementById("displayDayEl").innerHTML = zeroPad(day,2);
Expand Down
21 changes: 5 additions & 16 deletions wayback-webapp/src/main/webapp/WEB-INF/template/UI-header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%@ page import="org.archive.wayback.core.WaybackRequest" %>
<%@ page import="org.archive.wayback.core.UIResults" %>
<%@ page import="org.archive.wayback.util.StringFormatter" %>
<%@ page import="org.archive.wayback.util.Timestamp" %>
<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%
UIResults results = UIResults.getGeneric(request);
Expand Down Expand Up @@ -74,22 +75,10 @@ String replayPrefix = results.getReplayPrefix();
&nbsp;
</b>
<select name="<%= WaybackRequest.REQUEST_DATE %>" size="1">
<option value="" selected><%= fmt.format("UIGlobal.selectYearAll") %></option>
<option>2010</option>
<option>2009</option>
<option>2008</option>
<option>2007</option>
<option>2006</option>
<option>2005</option>
<option>2004</option>
<option>2003</option>
<option>2002</option>
<option>2001</option>
<option>2000</option>
<option>1999</option>
<option>1998</option>
<option>1997</option>
<option>1996</option>
<option value="" selected><%= fmt.format("UIGlobal.selectYearAll") %></option>
<% for(int i = Timestamp.getEndYear(); i >= Timestamp.getStartYear(); i-=1) { %>
<option><%= i %></option>
<% } %>
</select>
&nbsp;
<input type="submit" name="Submit" value="<%= fmt.format("UIGlobal.urlSearchButton") %>" align="absMiddle">
Expand Down
7 changes: 7 additions & 0 deletions wayback-webapp/src/main/webapp/WEB-INF/wayback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,11 @@
</bean>
-->

<!--
Set the minimum year that is handled by this server. If commented out the vaule of the
start year will default to 1996.
-->
<bean name="minimumYearAllowed" class="org.archive.wayback.util.Timestamp">
<property name="startYear" value="1996" />
</bean>
</beans>

0 comments on commit e6195c1

Please sign in to comment.