#3624 DateTimeFormat wrong - match pattern returned from servers (#3625)

This commit is contained in:
Seán Mac Gillicuddy 2020-04-08 17:39:41 +01:00 committed by GitHub
parent 6b075d9124
commit d7a42b2f89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -25,9 +25,10 @@ public class CommonsDateUtil {
* Gets the timestamp pattern for a date
* @return timestamp
*/
public static SimpleDateFormat getIso8601DateFormatTimestamp() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat;
public static SimpleDateFormat getIso8601DateFormatTimestamp() {
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX",
Locale.ROOT);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat;
}
}

View file

@ -0,0 +1,20 @@
package fr.free.nrw.commons.utils
import org.hamcrest.core.IsEqual.equalTo
import org.junit.Assert.assertThat
import org.junit.Test
class CommonsDateUtilTest {
@Test
fun `Iso8601DateFormatTimestamp parses legal date`() {
val iso8601DateFormatTimestamp = CommonsDateUtil
.getIso8601DateFormatTimestamp()
val parsedDate = iso8601DateFormatTimestamp
.parse("2020-04-07T14:21:57Z")
assertThat(
"2020-04-07T14:21:57Z",
equalTo(iso8601DateFormatTimestamp.format(parsedDate))
)
}
}