mirror of https://github.com/jwtk/jjwt.git
Merge pull request #357 from jwtk/291-sdf-utc
Fix claim assertion exception message to reflect UTC timestamps
This commit is contained in:
commit
ac6703541e
|
@ -4,6 +4,7 @@ import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.10.0
|
* @since 0.10.0
|
||||||
|
@ -17,14 +18,18 @@ public class DateFormats {
|
||||||
private static final ThreadLocal<DateFormat> ISO_8601 = new ThreadLocal<DateFormat>() {
|
private static final ThreadLocal<DateFormat> ISO_8601 = new ThreadLocal<DateFormat>() {
|
||||||
@Override
|
@Override
|
||||||
protected DateFormat initialValue() {
|
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>() {
|
private static final ThreadLocal<DateFormat> ISO_8601_MILLIS = new ThreadLocal<DateFormat>() {
|
||||||
@Override
|
@Override
|
||||||
protected DateFormat initialValue() {
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue