Resolves #291 (regression tests added)

This commit is contained in:
Les Hazlewood 2018-07-20 17:43:09 -04:00
parent 2eeca41a61
commit 7404fd130b
2 changed files with 32 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* @since 0.10.0
@ -17,14 +18,18 @@ public class DateFormats {
private static final ThreadLocal<DateFormat> ISO_8601 = new ThreadLocal<DateFormat>() {
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat(ISO_8601_PATTERN);
SimpleDateFormat format = new SimpleDateFormat(ISO_8601_PATTERN);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format;
}
};
private static final ThreadLocal<DateFormat> ISO_8601_MILLIS = new ThreadLocal<DateFormat>() {
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat(ISO_8601_MILLIS_PATTERN);
SimpleDateFormat format = new SimpleDateFormat(ISO_8601_MILLIS_PATTERN);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format;
}
};

View File

@ -0,0 +1,25 @@
package io.jsonwebtoken.lang
import org.junit.Test
import java.text.SimpleDateFormat
import static org.junit.Assert.*
class DateFormatsTest {
@Test //https://github.com/jwtk/jjwt/issues/291
void testUtcTimezone() {
def iso8601 = DateFormats.ISO_8601.get()
def iso8601Millis = DateFormats.ISO_8601_MILLIS.get()
assertTrue iso8601 instanceof SimpleDateFormat
assertTrue iso8601Millis instanceof SimpleDateFormat
def utc = TimeZone.getTimeZone("UTC")
assertEquals utc, iso8601.getTimeZone()
assertEquals utc, iso8601Millis.getTimeZone()
}
}