Skip to content

Commit cf73e28

Browse files
macgillsmisaochan
authored andcommitted
#3624 DateTimeFormat wrong - match pattern returned from servers (#3625)
1 parent 93d6c52 commit cf73e28

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

app/src/main/java/fr/free/nrw/commons/utils/CommonsDateUtil.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public static SimpleDateFormat getIso8601DateFormatShort() {
2525
* Gets the timestamp pattern for a date
2626
* @return timestamp
2727
*/
28-
public static SimpleDateFormat getIso8601DateFormatTimestamp() {
29-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
30-
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
31-
return simpleDateFormat;
28+
public static SimpleDateFormat getIso8601DateFormatTimestamp() {
29+
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX",
30+
Locale.ROOT);
31+
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
32+
return simpleDateFormat;
3233
}
3334
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fr.free.nrw.commons.utils
2+
3+
import org.hamcrest.core.IsEqual.equalTo
4+
import org.junit.Assert.assertThat
5+
import org.junit.Test
6+
7+
class CommonsDateUtilTest {
8+
9+
@Test
10+
fun `Iso8601DateFormatTimestamp parses legal date`() {
11+
val iso8601DateFormatTimestamp = CommonsDateUtil
12+
.getIso8601DateFormatTimestamp()
13+
val parsedDate = iso8601DateFormatTimestamp
14+
.parse("2020-04-07T14:21:57Z")
15+
assertThat(
16+
"2020-04-07T14:21:57Z",
17+
equalTo(iso8601DateFormatTimestamp.format(parsedDate))
18+
)
19+
}
20+
}

0 commit comments

Comments
 (0)