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

Feature/weather #47

Merged
merged 19 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add time to date
  • Loading branch information
AmeerAmjed committed Mar 2, 2024
commit 0f720ccbe9bdf7a8649ea8881126928920cbdb54
4 changes: 1 addition & 3 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ kotlin {
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
// implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$ktorVersion")
// implementation("com.google.code.gson:gson:2.10.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0-RC")

val coilVersion = "3.0.0-SNAPSHOT"
implementation("io.coil-kt.coil3:coil-compose:$coilVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.example.travelapp_kmp.utils

import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.format
import kotlinx.datetime.format.FormatStringsInDatetimeFormats
import kotlinx.datetime.format.byUnicodePattern
import kotlinx.datetime.toLocalDateTime

@OptIn(FormatStringsInDatetimeFormats::class)
fun convertTimestampToDate(timestamp: Int): String {
val instant = Instant.fromEpochSeconds(timestamp.toLong())
val localDateTime = instant.toLocalDateTime(TimeZone.currentSystemDefault())

val dayOfWeek = localDateTime.dayOfWeek.name.lowercase().replaceFirstChar { it.uppercase() }
val month = localDateTime.month.name.lowercase().replaceFirstChar { it.uppercase() }
val dayOfMonth = localDateTime.dayOfMonth
val time = localDateTime.format(LocalDateTime.Format { byUnicodePattern("HH:mm") })

return "$dayOfWeek, $month $dayOfMonth"
return "$dayOfWeek $dayOfMonth $month $time"
}