diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java index 9f3cd8e88..639ab17b8 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java @@ -29,25 +29,6 @@ import android.os.Bundle; public class OtherHelper { - /** - * Return the number if days between two dates - * - * @param first - * @param second - * @return number of days - */ - public static long getNumDaysBetween(GregorianCalendar first, GregorianCalendar second) { - GregorianCalendar tmp = new GregorianCalendar(); - tmp.setTime(first.getTime()); - long numDays = (second.getTimeInMillis() - first.getTimeInMillis()) / 1000 / 86400; - tmp.add(Calendar.DAY_OF_MONTH, (int) numDays); - while (tmp.before(second)) { - tmp.add(Calendar.DAY_OF_MONTH, 1); - ++numDays; - } - return numDays; - } - /** * Logs bundle content to debug for inspecting the content * diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index eed0ed256..d6f130682 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -28,6 +28,7 @@ import java.security.SignatureException; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; +import java.util.TimeZone; import org.spongycastle.bcpg.CompressionAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags; @@ -323,7 +324,7 @@ public class PgpKeyOperation { hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); if (keysExpiryDates.get(0) != null) { - GregorianCalendar creationDate = new GregorianCalendar(); + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); creationDate.setTime(masterPublicKey.getCreationTime()); GregorianCalendar expiryDate = keysExpiryDates.get(0); //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c @@ -402,7 +403,7 @@ public class PgpKeyOperation { hashedPacketsGen.setKeyFlags(false, keyFlags); if (keysExpiryDates.get(i) != null) { - GregorianCalendar creationDate = new GregorianCalendar(); + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); creationDate.setTime(subPublicKey.getCreationTime()); GregorianCalendar expiryDate = keysExpiryDates.get(i); //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index dba9ba1ad..6c265057e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -20,6 +20,7 @@ import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.TimeZone; import java.util.Vector; import org.spongycastle.openpgp.PGPPublicKey; @@ -64,7 +65,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // Note: Ignore results after the first one - android sends multiples. if (mDatePickerResultCount++ == 0) { - GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth); + GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + date.set(year, monthOfYear, dayOfMonth); setExpiryDate(date); } } @@ -109,7 +111,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public void onClick(View v) { GregorianCalendar date = mExpiryDate; if (date == null) { - date = new GregorianCalendar(); + date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); } DatePickerDialog dialog = new DatePickerDialog(getContext(), @@ -201,10 +203,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } - GregorianCalendar cal = new GregorianCalendar(); + GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime())); - cal = new GregorianCalendar(); + cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); Date expiryDate = PgpKeyHelper.getExpiryDate(key); if (expiryDate == null) { setExpiryDate(null); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java index 8b5e94858..fdcaf9258 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java @@ -29,6 +29,7 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.GregorianCalendar; import java.util.List; +import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -182,8 +183,11 @@ public class HkpKeyServer extends KeyServer { info.keyId = PgpKeyHelper.convertHexToKeyId(matcher.group(3)); info.fingerPrint = PgpKeyHelper.convertKeyIdToHex(info.keyId); String chunks[] = matcher.group(4).split("-"); - info.date = new GregorianCalendar(Integer.parseInt(chunks[0]), - Integer.parseInt(chunks[1]), Integer.parseInt(chunks[2])).getTime(); + + GregorianCalendar tmpGreg = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + tmpGreg.set(Integer.parseInt(chunks[0]), Integer.parseInt(chunks[1]), + Integer.parseInt(chunks[2])); + info.date = tmpGreg.getTime(); info.userIds = new ArrayList(); if (matcher.group(5).startsWith("*** KEY")) { info.revoked = matcher.group(5);