-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse new "start_date", "end_date", "event_timezone" properties into …
…Shift. + Deprecate "start", "end", "timezone" properties in favor of the new ones. + All new properties are mandatory in the JSON shift object which makes this change a breaking change.
- Loading branch information
1 parent
510250d
commit 4d5b1e2
Showing
8 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...src/main/kotlin/info/metadude/kotlin/library/engelsystem/adapters/ZonedDateTimeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package info.metadude.kotlin.library.engelsystem.adapters | ||
|
||
import com.squareup.moshi.FromJson | ||
import org.threeten.bp.DateTimeException | ||
import org.threeten.bp.ZonedDateTime | ||
|
||
class ZonedDateTimeAdapter { | ||
|
||
@FromJson | ||
fun fromJson(jsonValue: String?) = jsonValue?.let { | ||
try { | ||
ZonedDateTime.parse(jsonValue) | ||
} catch (e: DateTimeException) { | ||
println(e.message) | ||
null | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...main/kotlin/info/metadude/kotlin/library/engelsystem/adapters/ZonedDateTimeJsonAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package info.metadude.kotlin.library.engelsystem.adapters | ||
|
||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.JsonReader | ||
import com.squareup.moshi.JsonWriter | ||
import org.threeten.bp.ZonedDateTime | ||
|
||
class ZonedDateTimeJsonAdapter : JsonAdapter<ZonedDateTime>() { | ||
|
||
private val delegate = ZonedDateTimeAdapter() | ||
|
||
override fun fromJson(reader: JsonReader): ZonedDateTime? { | ||
val jsonValue = reader.nextString() | ||
return delegate.fromJson(jsonValue) | ||
} | ||
|
||
override fun toJson(writer: JsonWriter, value: ZonedDateTime?) { | ||
throw NotImplementedError() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...test/kotlin/info/metadude/kotlin/library/engelsystem/adapters/ZonedDateTimeAdapterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package info.metadude.kotlin.library.engelsystem.adapters | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.threeten.bp.ZoneOffset | ||
import org.threeten.bp.ZonedDateTime | ||
|
||
class ZonedDateTimeAdapterTest { | ||
|
||
private val adapter = ZonedDateTimeAdapter() | ||
|
||
@Test | ||
fun `Converts RFC3339 date to its ZonedDateTime representation`() { | ||
val actual = adapter.fromJson("2019-08-21T00:00:00+02:00") | ||
val expected = ZonedDateTime.of(2019, 8, 21, 0, 0, 0, 0, ZoneOffset.ofHours(2)) | ||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Converts date without zone offset to null`() { | ||
val actual = adapter.fromJson("2019-08-21T00:00:00") | ||
assertThat(actual).isEqualTo(null) | ||
} | ||
|
||
@Test | ||
fun `Converts 0 to null`() { | ||
val actual = adapter.fromJson("") | ||
assertThat(actual).isEqualTo(null) | ||
} | ||
|
||
@Test | ||
fun `Converts null to null`() { | ||
val actual = adapter.fromJson(null) | ||
assertThat(actual).isEqualTo(null) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters