From 946e6bf4f3cdb37fb51be92b4abd9930cccebf3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Wed, 12 Feb 2020 16:44:46 +0100 Subject: [PATCH] Rename String.toIso8601Date to String.iso8601ToDate --- .../java/org/readium/r2/shared/extensions/String.kt | 7 +++---- .../java/org/readium/r2/shared/opds/Availability.kt | 6 +++--- .../java/org/readium/r2/shared/publication/Metadata.kt | 4 ++-- .../org/readium/r2/shared/opds/AvailabilityTest.kt | 10 +++++----- .../org/readium/r2/shared/publication/MetadataTest.kt | 10 +++++----- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/extensions/String.kt b/r2-shared/src/main/java/org/readium/r2/shared/extensions/String.kt index 761a939f..edc5bb10 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/extensions/String.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/extensions/String.kt @@ -13,10 +13,9 @@ import org.joda.time.DateTime import org.joda.time.DateTimeZone import java.util.* -fun String.toIso8601Date(): Date? { +fun String.iso8601ToDate(): Date? = try { - return DateTime(this, DateTimeZone.UTC).toDate() + DateTime(this).toDate() } catch (e: Exception) { - return null + null } -} diff --git a/r2-shared/src/main/java/org/readium/r2/shared/opds/Availability.kt b/r2-shared/src/main/java/org/readium/r2/shared/opds/Availability.kt index 88b16124..34adb312 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/opds/Availability.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/opds/Availability.kt @@ -15,7 +15,7 @@ import org.json.JSONObject import org.readium.r2.shared.JSONable import org.readium.r2.shared.util.logging.WarningLogger import org.readium.r2.shared.extensions.optNullableString -import org.readium.r2.shared.extensions.toIso8601Date +import org.readium.r2.shared.extensions.iso8601ToDate import org.readium.r2.shared.extensions.toIso8601String import org.readium.r2.shared.util.KeyMapper import org.readium.r2.shared.util.logging.JsonWarning @@ -71,8 +71,8 @@ data class Availability( return Availability( state = state, - since = json?.optNullableString("since")?.toIso8601Date(), - until = json?.optNullableString("until")?.toIso8601Date() + since = json?.optNullableString("since")?.iso8601ToDate(), + until = json?.optNullableString("until")?.iso8601ToDate() ) } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/publication/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/publication/Metadata.kt index 51c7e821..d6bbf38c 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/publication/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/publication/Metadata.kt @@ -134,8 +134,8 @@ data class Metadata( val identifier = json.remove("identifier") as? String val type = json.remove("@type") as? String val localizedSubtitle = LocalizedString.fromJSON(json.remove("subtitle"), warnings) - val modified = (json.remove("modified") as? String)?.toIso8601Date() - val published = (json.remove("published") as? String)?.toIso8601Date() + val modified = (json.remove("modified") as? String)?.iso8601ToDate() + val published = (json.remove("published") as? String)?.iso8601ToDate() val languages = json.optStringsFromArrayOrSingle("language", remove = true) val sortAs = json.remove("sortAs") as? String val subjects = Subject.fromJSONArray(json.remove("subject"), normalizeHref, warnings) diff --git a/r2-shared/src/test/java/org/readium/r2/shared/opds/AvailabilityTest.kt b/r2-shared/src/test/java/org/readium/r2/shared/opds/AvailabilityTest.kt index 2621c4f6..0d61596c 100644 --- a/r2-shared/src/test/java/org/readium/r2/shared/opds/AvailabilityTest.kt +++ b/r2-shared/src/test/java/org/readium/r2/shared/opds/AvailabilityTest.kt @@ -4,7 +4,7 @@ import org.json.JSONObject import org.junit.Assert.* import org.junit.Test import org.readium.r2.shared.assertJSONEquals -import org.readium.r2.shared.extensions.toIso8601Date +import org.readium.r2.shared.extensions.iso8601ToDate class AvailabilityTest { @@ -35,8 +35,8 @@ class AvailabilityTest { assertEquals( Availability( state = Availability.State.AVAILABLE, - since = "2001-01-01T12:36:27.000Z".toIso8601Date(), - until = "2001-02-01T12:36:27.000Z".toIso8601Date() + since = "2001-01-01T12:36:27.000Z".iso8601ToDate(), + until = "2001-02-01T12:36:27.000Z".iso8601ToDate() ), Availability.fromJSON(JSONObject("""{ 'state': 'available', @@ -70,8 +70,8 @@ class AvailabilityTest { }"""), Availability( state = Availability.State.AVAILABLE, - since = "2001-01-01T12:36:27.000Z".toIso8601Date(), - until = "2001-02-01T12:36:27.000Z".toIso8601Date() + since = "2001-01-01T12:36:27.000Z".iso8601ToDate(), + until = "2001-02-01T12:36:27.000Z".iso8601ToDate() ).toJSON() ) } diff --git a/r2-shared/src/test/java/org/readium/r2/shared/publication/MetadataTest.kt b/r2-shared/src/test/java/org/readium/r2/shared/publication/MetadataTest.kt index 56ce765a..508f7e82 100644 --- a/r2-shared/src/test/java/org/readium/r2/shared/publication/MetadataTest.kt +++ b/r2-shared/src/test/java/org/readium/r2/shared/publication/MetadataTest.kt @@ -13,7 +13,7 @@ import org.json.JSONObject import org.junit.Assert.* import org.junit.Test import org.readium.r2.shared.assertJSONEquals -import org.readium.r2.shared.extensions.toIso8601Date +import org.readium.r2.shared.extensions.iso8601ToDate class MetadataTest { @@ -37,8 +37,8 @@ class MetadataTest { "en" to "Subtitle", "fr" to "Sous-titre" )), - modified = "2001-01-01T12:36:27.000Z".toIso8601Date(), - published = "2001-01-02T12:36:27.000Z".toIso8601Date(), + modified = "2001-01-01T12:36:27.000Z".iso8601ToDate(), + published = "2001-01-02T12:36:27.000Z".iso8601ToDate(), languages = listOf("en", "fr"), sortAs = "sort key", subjects = listOf(Subject(name = "Science Fiction"), Subject(name = "Fantasy")), @@ -198,8 +198,8 @@ class MetadataTest { "en" to "Subtitle", "fr" to "Sous-titre" )), - modified = "2001-01-01T12:36:27.000Z".toIso8601Date(), - published = "2001-01-02T12:36:27.000Z".toIso8601Date(), + modified = "2001-01-01T12:36:27.000Z".iso8601ToDate(), + published = "2001-01-02T12:36:27.000Z".iso8601ToDate(), languages = listOf("en", "fr"), sortAs = "sort key", subjects = listOf(Subject(name = "Science Fiction"), Subject(name = "Fantasy")),