From ab3340d20bfccd5209ea0b2835223a134f58c59d Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Tue, 12 Jul 2016 13:07:21 +0200 Subject: [PATCH] Fixed some time zone issues --- .../sf/jabref/logic/layout/format/CurrentDate.java | 4 ++-- src/main/java/net/sf/jabref/logic/net/Cookie.java | 14 +++++++------- .../sf/jabref/logic/util/date/EasyDateFormat.java | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/layout/format/CurrentDate.java b/src/main/java/net/sf/jabref/logic/layout/format/CurrentDate.java index e22e0a4f1c0e..8fcdecaf9061 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/CurrentDate.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/CurrentDate.java @@ -25,7 +25,7 @@ */ package net.sf.jabref.logic.layout.format; -import java.time.LocalDate; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import net.sf.jabref.logic.layout.LayoutFormatter; @@ -55,6 +55,6 @@ public String format(String fieldText) { if ((fieldText != null) && (fieldText.trim() != null) && !fieldText.trim().isEmpty()) { format = fieldText; } - return LocalDate.now().format(DateTimeFormatter.ofPattern(format)); + return ZonedDateTime.now().format(DateTimeFormatter.ofPattern(format)); } } diff --git a/src/main/java/net/sf/jabref/logic/net/Cookie.java b/src/main/java/net/sf/jabref/logic/net/Cookie.java index 6e0df4bcf6a1..34e5c9e79d14 100644 --- a/src/main/java/net/sf/jabref/logic/net/Cookie.java +++ b/src/main/java/net/sf/jabref/logic/net/Cookie.java @@ -16,7 +16,7 @@ package net.sf.jabref.logic.net; import java.net.URI; -import java.time.LocalDate; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.Locale; @@ -27,12 +27,12 @@ class Cookie { private final String name; private final String value; private String domain; - private LocalDate expires; + private ZonedDateTime expires; private String path; - private final DateTimeFormatter whiteSpaceFormat = DateTimeFormatter.ofPattern("E, dd MMM yyyy k:m:s 'GMT'", + private final DateTimeFormatter whiteSpaceFormat = DateTimeFormatter.ofPattern("E, dd MMM yyyy k:m:s z", Locale.US); - private final DateTimeFormatter hyphenFormat = DateTimeFormatter.ofPattern("E, dd-MMM-yyyy k:m:s 'GMT'", Locale.US); + private final DateTimeFormatter hyphenFormat = DateTimeFormatter.ofPattern("E, dd-MMM-yyyy k:m:s z", Locale.US); /** @@ -78,10 +78,10 @@ public Cookie(URI uri, String header) { this.path = value; } else if ("expires".equalsIgnoreCase(name)) { try { - this.expires = LocalDate.parse(value, whiteSpaceFormat); + this.expires = ZonedDateTime.parse(value, whiteSpaceFormat); } catch (DateTimeParseException e) { try { - this.expires = LocalDate.parse(value, hyphenFormat); + this.expires = ZonedDateTime.parse(value, hyphenFormat); } catch (DateTimeParseException e2) { throw new IllegalArgumentException( "Bad date format in header: " + value); @@ -95,7 +95,7 @@ public boolean hasExpired() { if (expires == null) { return false; } - return LocalDate.now().isAfter(expires); + return ZonedDateTime.now().isAfter(expires); } /** diff --git a/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java b/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java index 82c99bf9746c..3fbd1dcea117 100644 --- a/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java +++ b/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java @@ -1,7 +1,7 @@ package net.sf.jabref.logic.util.date; -import java.time.LocalDate; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; @@ -35,7 +35,7 @@ public String getCurrentDate() { * @return The date string. */ public String getCurrentDate(boolean isoFormat) { - return getDateAt(LocalDate.now(), isoFormat); + return getDateAt(ZonedDateTime.now(), isoFormat); } /** @@ -45,7 +45,7 @@ public String getCurrentDate(boolean isoFormat) { * @return The formatted date string. */ public String getDateAt(Date date, boolean isoFormat) { - return getDateAt(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), isoFormat); + return getDateAt(date.toInstant().atZone(ZoneId.systemDefault()), isoFormat); } /** @@ -54,7 +54,7 @@ public String getDateAt(Date date, boolean isoFormat) { * * @return The formatted date string. */ - public String getDateAt(LocalDate localDate, boolean isoFormat) { + public String getDateAt(ZonedDateTime dateTime, boolean isoFormat) { // first use, create an instance if ((dateFormatter == null) || (isoFormat != isISOFormat)) { if (isoFormat) { @@ -65,6 +65,6 @@ public String getDateAt(LocalDate localDate, boolean isoFormat) { } isISOFormat = isoFormat; } - return localDate.format(dateFormatter); + return dateTime.format(dateFormatter); } }