Skip to content

Commit

Permalink
Fixed some time zone issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jul 13, 2016
1 parent 0e88f43 commit ab3340d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
14 changes: 7 additions & 7 deletions src/main/java/net/sf/jabref/logic/net/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);


/**
Expand Down Expand Up @@ -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);
Expand All @@ -95,7 +95,7 @@ public boolean hasExpired() {
if (expires == null) {
return false;
}
return LocalDate.now().isAfter(expires);
return ZonedDateTime.now().isAfter(expires);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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) {
Expand All @@ -65,6 +65,6 @@ public String getDateAt(LocalDate localDate, boolean isoFormat) {
}
isISOFormat = isoFormat;
}
return localDate.format(dateFormatter);
return dateTime.format(dateFormatter);
}
}

0 comments on commit ab3340d

Please sign in to comment.