Browse Source

change storage of timestamps in model to Instant

Armin Schrenk 11 months ago
parent
commit
060f6bfc97

+ 9 - 12
src/main/java/org/cryptomator/common/settings/Settings.java

@@ -25,10 +25,7 @@ import javafx.beans.property.StringProperty;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.geometry.NodeOrientation;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZoneOffset;
+import java.time.Instant;
 import java.util.Date;
 import java.util.function.Consumer;
 
@@ -49,8 +46,8 @@ public class Settings {
 	static final String DEFAULT_KEYCHAIN_PROVIDER = SystemUtils.IS_OS_WINDOWS ? "org.cryptomator.windows.keychain.WindowsProtectedKeychainAccess" : SystemUtils.IS_OS_MAC ? "org.cryptomator.macos.keychain.MacSystemKeychainAccess" : "org.cryptomator.linux.keychain.SecretServiceKeychainAccess";
 	static final String DEFAULT_USER_INTERFACE_ORIENTATION = NodeOrientation.LEFT_TO_RIGHT.name();
 	static final boolean DEFAULT_SHOW_MINIMIZE_BUTTON = false;
-	static final Date DEFAULT_LAST_UPDATE_REMINDER = Date.from(LocalDate.of(2000,1,1).atStartOfDay(ZoneId.systemDefault()).toInstant());
-	public static final Date DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK = Date.from(LocalDateTime.of(2000,1,1,1,0,0).toInstant(ZoneOffset.UTC));
+	static final Instant DEFAULT_LAST_UPDATE_REMINDER = Instant.ofEpochSecond(946681200); //2000-01-01T00:00:00Z
+	public static final Instant DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK = Instant.ofEpochSecond(946681200); //2000-01-01T00:00:00Z
 	public final ObservableList<VaultSettings> directories;
 	public final BooleanProperty askedForUpdateCheck;
 	public final BooleanProperty checkForUpdates;
@@ -72,8 +69,8 @@ public class Settings {
 	public final IntegerProperty windowHeight;
 	public final StringProperty language;
 	public final StringProperty mountService;
-	public final ObjectProperty<Date> lastUpdateReminder;
-	public final ObjectProperty<Date> lastSuccessfulUpdateCheck;
+	public final ObjectProperty<Instant> lastUpdateReminder;
+	public final ObjectProperty<Instant> lastSuccessfulUpdateCheck;
 	public final StringProperty latestVersion;
 
 	private Consumer<Settings> saveCmd;
@@ -111,8 +108,8 @@ public class Settings {
 		this.windowHeight = new SimpleIntegerProperty(this, "windowHeight", json.windowHeight);
 		this.language = new SimpleStringProperty(this, "language", json.language);
 		this.mountService = new SimpleStringProperty(this, "mountService", json.mountService);
-		this.lastUpdateReminder = new SimpleObjectProperty<>(this, "lastUpdateReminder", json.lastUpdateReminder);
-		this.lastSuccessfulUpdateCheck = new SimpleObjectProperty<>(this, "lastSuccessfulUpdateCheck", json.lastSuccessfulUpdateCheck);
+		this.lastUpdateReminder = new SimpleObjectProperty<>(this, "lastUpdateReminder", json.lastUpdateReminder.toInstant());
+		this.lastSuccessfulUpdateCheck = new SimpleObjectProperty<>(this, "lastSuccessfulUpdateCheck", json.lastSuccessfulUpdateCheck.toInstant());
 		this.latestVersion = new SimpleStringProperty(this, "latestVersion", json.latestVersion);
 
 		this.directories.addAll(json.directories.stream().map(VaultSettings::new).toList());
@@ -197,8 +194,8 @@ public class Settings {
 		json.windowHeight = windowHeight.get();
 		json.language = language.get();
 		json.mountService = mountService.get();
-		json.lastUpdateReminder = lastUpdateReminder.get();
-		json.lastSuccessfulUpdateCheck = lastSuccessfulUpdateCheck.get();
+		json.lastUpdateReminder = Date.from(lastUpdateReminder.get());
+		json.lastSuccessfulUpdateCheck = Date.from(lastSuccessfulUpdateCheck.get());
 		json.latestVersion = latestVersion.get();
 		return json;
 	}

+ 2 - 3
src/main/java/org/cryptomator/common/settings/SettingsJson.java

@@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-import java.time.LocalDate;
 import java.util.Date;
 import java.util.List;
 
@@ -85,11 +84,11 @@ class SettingsJson {
 
 	@JsonProperty("lastUpdateReminder")
 	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
-	Date lastUpdateReminder = Settings.DEFAULT_LAST_UPDATE_REMINDER;
+	Date lastUpdateReminder = Date.from(Settings.DEFAULT_LAST_UPDATE_REMINDER);
 
 	@JsonProperty("lastSuccessfulUpdateCheck")
 	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
-	Date lastSuccessfulUpdateCheck = Settings.DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK;
+	Date lastSuccessfulUpdateCheck = Date.from(Settings.DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK);
 
 	@JsonProperty("latestVersion")
 	String latestVersion;