Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public static SimpleDateFormat getIso8601DateFormatShort() {
* 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;
}
}
Original file line number Diff line number Diff line change
@@ -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))
)
}
}