Port snapshot commands, update some time stuff to new time

This commit is contained in:
Kenzie Togami
2019-04-23 23:47:22 -07:00
parent ea3605204c
commit 2ea30dc70e
8 changed files with 172 additions and 125 deletions

View File

@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.time.ZonedDateTime;
import java.util.zip.ZipFile;
/**
@ -46,7 +46,7 @@ public class Snapshot implements Comparable<Snapshot> {
protected File file;
protected String name;
protected Calendar date;
protected ZonedDateTime date;
/**
* Construct a snapshot restoration operation.
@ -185,7 +185,7 @@ public class Snapshot implements Comparable<Snapshot> {
*
* @return date for the snapshot
*/
public Calendar getDate() {
public ZonedDateTime getDate() {
return date;
}
@ -194,7 +194,7 @@ public class Snapshot implements Comparable<Snapshot> {
*
* @param date the date of the snapshot
*/
public void setDate(Calendar date) {
public void setDate(ZonedDateTime date) {
this.date = date;
}

View File

@ -23,15 +23,16 @@ package com.sk89q.worldedit.world.snapshot;
import com.sk89q.worldedit.world.storage.MissingWorldException;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FilenameFilter;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
/**
* A repository contains zero or more snapshots.
*/
@ -115,12 +116,12 @@ public class SnapshotRepository {
* @return a snapshot or null
*/
@Nullable
public Snapshot getSnapshotAfter(Calendar date, String world) throws MissingWorldException {
public Snapshot getSnapshotAfter(ZonedDateTime date, String world) throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(true, world);
Snapshot last = null;
for (Snapshot snapshot : snapshots) {
if (snapshot.getDate() != null && snapshot.getDate().before(date)) {
if (snapshot.getDate() != null && snapshot.getDate().compareTo(date) < 0) {
return last;
}
@ -137,12 +138,12 @@ public class SnapshotRepository {
* @return a snapshot or null
*/
@Nullable
public Snapshot getSnapshotBefore(Calendar date, String world) throws MissingWorldException {
public Snapshot getSnapshotBefore(ZonedDateTime date, String world) throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(false, world);
Snapshot last = null;
for (Snapshot snapshot : snapshots) {
if (snapshot.getDate().after(date)) {
if (snapshot.getDate().compareTo(date) > 0) {
return last;
}
@ -161,7 +162,7 @@ public class SnapshotRepository {
for (SnapshotDateParser parser : dateParsers) {
Calendar date = parser.detectDate(snapshot.getFile());
if (date != null) {
snapshot.setDate(date);
snapshot.setDate(date.toInstant().atZone(ZoneOffset.UTC));
return;
}
}