mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Fix kdbx4 date corruption
This commit is contained in:
1 parent
a7b5fd512a
commit
77c8207c73
2 files changed
+23
-3
No files matched your search
@@ -922,7 +922,7 @@ public class ImporterV4 extends Importer {
|
||||
byte[] buf = Base64Coder.decode(sDate);
|
||||
if (buf.length != 8) {
|
||||
byte[] buf8 = new byte[8];
|
||||
System.arraycopy(buf, 0, buf8, 0, buf.length);
|
||||
System.arraycopy(buf, 0, buf8, 0, Math.min(buf.length, 8));
|
||||
buf = buf8;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,17 +21,37 @@ package com.keepassdroid.utils;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.Seconds;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtil {
|
||||
private static final DateTime dotNetEpoch = new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC);
|
||||
private static final DateTime javaEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeZone.UTC);
|
||||
|
||||
private static final long epochOffset;
|
||||
|
||||
static {
|
||||
Date dotNet = dotNetEpoch.toDate();
|
||||
Date java = javaEpoch.toDate();
|
||||
|
||||
epochOffset = (javaEpoch.getMillis() - dotNetEpoch.getMillis()) / 1000L;
|
||||
}
|
||||
|
||||
public static Date convertKDBX4Time(long seconds) {
|
||||
return dotNetEpoch.plus(seconds).toDate();
|
||||
|
||||
DateTime dt = dotNetEpoch.plus(seconds * 1000L);
|
||||
|
||||
// Switch corrupted dates to a more recent date that won't cause issues on the client
|
||||
if (dt.isBefore(javaEpoch)) {
|
||||
return javaEpoch.toDate();
|
||||
}
|
||||
|
||||
return dt.toDate();
|
||||
}
|
||||
|
||||
public static long convertDateToKDBX4Time(DateTime dt) {
|
||||
return (dt.getMillis() / 1000) - (dotNetEpoch.getMillis() / 1000);
|
||||
Seconds secs = Seconds.secondsBetween(javaEpoch, dt);
|
||||
return secs.getSeconds() + epochOffset;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user