Skip to content
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

Support GitLab different time zones on the JSON #169

Merged
merged 3 commits into from
May 7, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Master

- Update kotlinx-datetime to 0.1.1 [@f-meloni] - [@gianluz] - [#167](https://github.com/danger/kotlin/pull/167)
- Support GitLab different time zones on the JSON [@f-meloni] - [#169](https://github.com/danger/kotlin/pull/169)

# 1.0.0-beta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.*

@ExperimentalSerializationApi
@Serializer(forClass = DateSerializer::class)
Expand All @@ -22,6 +25,25 @@ object DateSerializer : KSerializer<Instant> {
}

override fun deserialize(decoder: Decoder): Instant {
return Instant.parse(decoder.decodeString())
val value = decoder.decodeString()

return try {
Instant.parse(value)
} catch(e: Throwable) {
Instant.fromEpochMilliseconds(GitLabISO8601DateFormat().parse(value).toInstant().toEpochMilli())
}
}
}

class GitLabISO8601DateFormat {
fun parse(string: String?): Date {
val formatter = SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
).apply {
timeZone = TimeZone.getTimeZone("UTC")
}

return formatter.parse(string.toString())
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GitLabParsingTests {
assertEquals(27469633, id)
assertEquals(182, iid)
assertEquals(Instant.fromEpochMilliseconds(1554942802492), latestBuildFinishedAt)
assertEquals(Instant.fromEpochMilliseconds(1554942022492), latestBuildStartedAt)
assertEquals(Instant.fromEpochMilliseconds(1619786100103), latestBuildStartedAt)
assertEquals(listOf<String>(), labels)
assertEquals("377a24fb7a0f30364f089f7bca67752a8b61f477", mergeCommitSha)
assertEquals(Instant.fromEpochMilliseconds(1554943042492), mergedAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"squash": false,
"subscribed": false,
"changes_count": "1",
"latest_build_started_at": "2019-04-11T00:20:22.492Z",
"latest_build_started_at": "2021-04-30T14:35:00.103+02:00",
"latest_build_finished_at": "2019-04-11T00:33:22.492Z",
"first_deployed_to_production_at": "2019-04-11T00:30:22.492Z",
"pipeline": {
Expand Down