generalized time period computations

This commit is contained in:
Michael Peter Christen 2015-03-02 12:55:31 +01:00
parent dcfc384eee
commit 710a0efa1b
6 changed files with 27 additions and 23 deletions

View File

@ -33,6 +33,7 @@ import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.document.encoding.ASCII;
import net.yacy.cora.document.id.AnchorURL;
import net.yacy.cora.document.id.DigestURL;
@ -725,11 +726,11 @@ public class Crawler_p {
private static Date timeParser(final boolean recrawlIfOlderCheck, final int number, final String unit) {
if (!recrawlIfOlderCheck) return null;
if ("year".equals(unit)) return new Date(System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L * 365L);
if ("month".equals(unit)) return new Date(System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L * 30L);
if ("day".equals(unit)) return new Date(System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L);
if ("hour".equals(unit)) return new Date(System.currentTimeMillis() - number * 1000L * 60L * 60L);
if ("minute".equals(unit)) return new Date(System.currentTimeMillis() - number * 1000L * 60L);
if ("year".equals(unit)) return new Date(System.currentTimeMillis() - number * AbstractFormatter.normalyearMillis);
if ("month".equals(unit)) return new Date(System.currentTimeMillis() - number * AbstractFormatter.monthAverageMillis);
if ("day".equals(unit)) return new Date(System.currentTimeMillis() - number * AbstractFormatter.dayMillis);
if ("hour".equals(unit)) return new Date(System.currentTimeMillis() - number * AbstractFormatter.hourMillis);
if ("minute".equals(unit)) return new Date(System.currentTimeMillis() - number * AbstractFormatter.minuteMillis);
return null;
}

View File

@ -29,6 +29,7 @@ import java.util.regex.Pattern;
import org.apache.solr.common.SolrDocument;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.federate.solr.connector.AbstractSolrConnector;
@ -263,11 +264,11 @@ public class IndexDeletion_p {
}
private static long timeParser(final int number, final String unit) {
if ("year".equals(unit)) return System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L * 365L;
if ("month".equals(unit)) return System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L * 30L;
if ("day".equals(unit)) return System.currentTimeMillis() - number * 1000L * 60L * 60L * 24L;
if ("hour".equals(unit)) return System.currentTimeMillis() - number * 1000L * 60L * 60L;
if ("minute".equals(unit)) return System.currentTimeMillis() - number * 1000L * 60L;
if ("year".equals(unit)) return System.currentTimeMillis() - number * AbstractFormatter.normalyearMillis;
if ("month".equals(unit)) return System.currentTimeMillis() - number * AbstractFormatter.monthAverageMillis;
if ("day".equals(unit)) return System.currentTimeMillis() - number * AbstractFormatter.dayMillis;
if ("hour".equals(unit)) return System.currentTimeMillis() - number * AbstractFormatter.hourMillis;
if ("minute".equals(unit)) return System.currentTimeMillis() - number * AbstractFormatter.minuteMillis;
return 0L;
}

View File

@ -29,6 +29,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.document.encoding.UTF8;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
@ -165,7 +166,7 @@ public class Table_API_p {
Iterator<Row> ri = sb.tables.iterator(WorkTables.TABLE_API_NAME);
Row row;
Date now = new Date();
Date limit = new Date(now.getTime() - 1000L * 60L * 60L * 24L * days);
Date limit = new Date(now.getTime() - AbstractFormatter.dayMillis * days);
List<byte[]> pkl = new ArrayList<byte[]>();
while (ri.hasNext()) {
row = ri.next();

View File

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.sorting.OrderedScoreMap;
@ -59,12 +60,12 @@ public final class timeline_p {
if (period.length() > 0) {
char c = period.charAt(period.length() - 1);
long p = Long.parseLong(period.substring(0, period.length() - 1));
if (c == 's') periodlength = p * 1000L;
else if (c == 'm') periodlength = p * 1000L * 60L;
else if (c == 'h') periodlength = p * 1000L * 60L * 60L;
else if (c == 'd') periodlength = p * 1000L * 60L * 60L * 24L;
else if (c == 'M') periodlength = p * 1000L * 60L * 60L * 24L * 30L;
else if (c == 'Y' || c == 'y') periodlength = p * 1000L * 60L * 60L * 24L * 365L;
if (c == 's') periodlength = p * AbstractFormatter.secondMillis;
else if (c == 'm') periodlength = p * AbstractFormatter.minuteMillis;
else if (c == 'h') periodlength = p * AbstractFormatter.hourMillis;
else if (c == 'd') periodlength = p * AbstractFormatter.dayMillis;
else if (c == 'M') periodlength = p * AbstractFormatter.monthAverageMillis;
else if (c == 'Y' || c == 'y') periodlength = p * AbstractFormatter.normalyearMillis;
else periodlength = 0;
}
final String[] data = CommonPattern.COMMA.split(post.get("data", "")); // a string of word hashes that shall be searched and combined

View File

@ -28,6 +28,7 @@ import java.util.Map;
import org.apache.solr.schema.TrieDateField;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.document.analysis.Classification;
import net.yacy.cora.document.analysis.Classification.ContentDomain;
import net.yacy.cora.document.id.MultiProtocolURL;
@ -378,11 +379,10 @@ public class yacysearchtrailer {
navigatorIterator = theSearch.dateNavigator.iterator(); // this iterator is different as it iterates by the key order (which is a date order)
int i = 0, pos = 0, neg = 0;
long dx = -1;
long dayms = 1000L * 60L * 60L * 24L;
Date fromconstraint = theSearch.getQuery().modifier.from == null ? null : DateDetection.parseLine(theSearch.getQuery().modifier.from);
if (fromconstraint == null) fromconstraint = new Date(System.currentTimeMillis() - 365 * dayms);
if (fromconstraint == null) fromconstraint = new Date(System.currentTimeMillis() - AbstractFormatter.normalyearMillis);
Date toconstraint = theSearch.getQuery().modifier.to == null ? null : DateDetection.parseLine(theSearch.getQuery().modifier.to);
if (toconstraint == null) toconstraint = new Date(System.currentTimeMillis() + 365 * dayms);
if (toconstraint == null) toconstraint = new Date(System.currentTimeMillis() + AbstractFormatter.normalyearMillis);
while (i < QueryParams.FACETS_DATE_MAXCOUNT && navigatorIterator.hasNext()) {
name = navigatorIterator.next().trim();
if (name.length() < 10) continue;
@ -394,8 +394,8 @@ public class yacysearchtrailer {
if (fromconstraint != null && dd.before(fromconstraint)) continue;
if (toconstraint != null && dd.after(toconstraint)) break;
if (dx > 0) {
while (d - dx > dayms) {
dx += dayms;
while (d - dx > AbstractFormatter.dayMillis) {
dx += AbstractFormatter.dayMillis;
String sn = TrieDateField.formatExternal(new Date(dx)).substring(0, 10);
prop.put("nav-dates_element_" + i + "_on", 0);
prop.put(fileType, "nav-dates_element_" + i + "_name", sn);

View File

@ -37,6 +37,7 @@ public abstract class AbstractFormatter implements DateFormatter {
public final static long minuteMillis = 60 * secondMillis;
public final static long hourMillis = 60 * minuteMillis;
public final static long dayMillis = 24 * hourMillis;
public final static long monthAverageMillis = 30 * dayMillis;
public final static long normalyearMillis = 365 * dayMillis;
public final static long leapyearMillis = 366 * dayMillis;
@ -49,5 +50,4 @@ public abstract class AbstractFormatter implements DateFormatter {
public abstract String format(final Date date);
@Override
public abstract String format();
}