Skip to content

Commit

Permalink
Merge pull request #609 from internetarchive/remove-joda-time
Browse files Browse the repository at this point in the history
Remove joda-time
  • Loading branch information
ato authored Oct 9, 2024
2 parents 2e891bc + 3c80dac commit 043dc4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
14 changes: 6 additions & 8 deletions commons/src/main/java/org/archive/io/Arc2Warc.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -50,17 +52,15 @@
import org.archive.uid.UUIDGenerator;
import org.archive.util.FileUtils;
import org.archive.util.anvl.ANVLRecord;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;


/**
* Convert ARCs to (sortof) WARCs.
* @author stack
* @version $Date$ $Revision$
*/
public class Arc2Warc {
private static final DateTimeFormatter ARC_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
.withZone(ZoneOffset.UTC);
protected RecordIDGenerator generator = new UUIDGenerator();

private static void usage(HelpFormatter formatter, Options options,
Expand Down Expand Up @@ -156,10 +156,8 @@ protected void write(final WARCWriter writer, final ARCRecord r)

// convert ARC date to WARC-Date format
String arcDateString = r.getHeader().getDate();
String warcDateString = DateTimeFormat.forPattern("yyyyMMddHHmmss")
.withZone(DateTimeZone.UTC)
.parseDateTime(arcDateString)
.toString(ISODateTimeFormat.dateTimeNoMillis());

String warcDateString = DateTimeFormatter.ISO_DATE_TIME.format(ARC_DATE_FORMAT.parse(arcDateString));
recordInfo.setCreate14DigitDate(warcDateString);

ANVLRecord ar = new ANVLRecord();
Expand Down
5 changes: 0 additions & 5 deletions engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@
<artifactId>org.restlet.ext.crypto</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6</version>
</dependency>
<!-- jaxb is no longer included in jdk11+ -->
<dependency>
<groupId>javax.xml.bind</groupId>
Expand Down
20 changes: 10 additions & 10 deletions engine/src/main/java/org/archive/crawler/framework/CrawlJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -68,7 +69,6 @@
import org.archive.util.ArchiveUtils;
import org.archive.util.ObjectIdentityCache;
import org.archive.util.TextUtils;
import org.joda.time.DateTime;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
Expand Down Expand Up @@ -98,10 +98,10 @@ public class CrawlJob implements Comparable<CrawlJob>, ApplicationListener<Appli
protected PathSharingContext ac;
protected int launchCount;
protected boolean isLaunchInfoPartial;
protected DateTime lastLaunch;
protected Instant lastLaunch;
protected AlertThreadGroup alertThreadGroup;

protected DateTime xmlOkAt = new DateTime(0L);
protected Instant xmlOkAt = Instant.ofEpochMilli(0);
protected Logger jobLogger;

public CrawlJob(File cxml) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public Logger getJobLogger() {
return jobLogger;
}

public DateTime getLastLaunch() {
public Instant getLastLaunch() {
return lastLaunch;
}
public int getLaunchCount() {
Expand Down Expand Up @@ -191,7 +191,7 @@ protected void scanJobLog() {
Matcher m = launchLine.matcher(line);
if (m.matches()) {
launchCount++;
lastLaunch = new DateTime(m.group(1));
lastLaunch = Instant.parse(m.group(1));
}
}
jobLogReader.close();
Expand Down Expand Up @@ -251,14 +251,14 @@ public void writeHtmlTo(PrintWriter pw, String uriPrefix) {
public void checkXML() {
// TODO: suppress check if XML unchanged? job.log when XML changed?

DateTime testTime = new DateTime(getPrimaryConfig().lastModified());
Instant testTime = Instant.ofEpochMilli(getPrimaryConfig().lastModified());
Document doc = getDomDocument(getPrimaryConfig());
// TODO: check for other minimal requirements, like
// presence of a few key components (CrawlController etc.)?
if(doc!=null) {
xmlOkAt = testTime;
} else {
xmlOkAt = new DateTime(0L);
xmlOkAt = Instant.ofEpochMilli(0);
}

}
Expand Down Expand Up @@ -290,7 +290,7 @@ protected Document getDomDocument(File f) {
* @return true if the primary configuration file passed XML testing
*/
public boolean isXmlOk() {
return xmlOkAt.getMillis() >= getPrimaryConfig().lastModified();
return xmlOkAt.toEpochMilli() >= getPrimaryConfig().lastModified();
}


Expand Down Expand Up @@ -588,7 +588,7 @@ protected synchronized void doTeardown() {
// all this stuff should happen even in case ac.close() bugs out
ac = null;

xmlOkAt = new DateTime(0);
xmlOkAt = Instant.ofEpochMilli(0);

if (currentLaunchJobLogHandler != null) {
getJobLogger().removeHandler(currentLaunchJobLogHandler);
Expand All @@ -615,7 +615,7 @@ public class JobLogFormatter extends Formatter {
public String format(LogRecord record) {
StringBuilder sb = new StringBuilder();
sb
.append(new DateTime(record.getMillis()))
.append(Instant.ofEpochMilli(record.getMillis()))
.append(" ")
.append(record.getLevel())
.append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String doubleToString(double number, int digits){
}
public String getLastLaunchTime(){
long ago = System.currentTimeMillis()
- crawlJob.getLastLaunch().getMillis();
- crawlJob.getLastLaunch().toEpochMilli();
return ArchiveUtils.formatMillisecondsToConventional(ago, 2);
}
/*
Expand Down

0 comments on commit 043dc4e

Please sign in to comment.