Skip to content

Commit

Permalink
Merge pull request #66 from capcom6/issue/65-android-6-date-format
Browse files Browse the repository at this point in the history
Fix timezone formatting for Android 6 and below in Local Server mode
  • Loading branch information
capcom6 committed May 8, 2024
2 parents 047bc38 + f268044 commit bc860c1
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import me.capcom.smsgateway.modules.messages.data.SendRequest
import me.capcom.smsgateway.modules.notifications.NotificationsService
import org.koin.android.ext.android.inject
import java.util.Date
import java.util.TimeZone
import kotlin.concurrent.thread

class WebService : Service() {
Expand Down Expand Up @@ -76,10 +77,24 @@ class WebService : Service() {
if (me.capcom.smsgateway.BuildConfig.DEBUG) {
setPrettyPrinting()
}
// ISO_8601
this.setDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
this.setDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
)
} else {
//get device timezone
val timeZone = TimeZone.getDefault()
this.setDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS" + when (timeZone.rawOffset) {
0 -> "Z"
else -> "+" + (timeZone.rawOffset / 3600000).toString().padStart(
2,
'0'
) + ":" + ((timeZone.rawOffset % 3600000) / 60000).toString()
.padStart(2, '0')
}
)
}
}
}
install(StatusPages) {
Expand Down

0 comments on commit bc860c1

Please sign in to comment.