-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate sample to use kotlinx.datetime
- Loading branch information
Showing
15 changed files
with
41 additions
and
3,073 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
This file was deleted.
Oops, something went wrong.
11 changes: 9 additions & 2 deletions
11
sample/common/src/commonMain/kotlin/com/example/sqldelight/hockey/data/Date.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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package com.example.sqldelight.hockey.data | ||
|
||
import app.cash.sqldelight.ColumnAdapter | ||
import kotlinx.datetime.LocalDate | ||
|
||
expect class Date(year: Int, month: Int, day: Int) | ||
class DateAdapter : ColumnAdapter<LocalDate, Long> { | ||
override fun decode(databaseValue: Long): LocalDate { | ||
return LocalDate.fromEpochDays(databaseValue.toInt()) | ||
} | ||
|
||
expect class DateAdapter() : ColumnAdapter<Date, Long> | ||
override fun encode(value: LocalDate): Long { | ||
return value.toEpochDays().toLong() | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...e/common/src/commonMain/kotlin/com/example/sqldelight/hockey/platform/DateFormatHelper.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package com.example.sqldelight.hockey.platform | ||
|
||
import com.example.sqldelight.hockey.data.Date | ||
import kotlinx.datetime.LocalDate | ||
|
||
expect class DateFormatHelper(format: String) { | ||
fun format(d: Date): String | ||
fun format(d: LocalDate): String | ||
} | ||
|
||
val defaultFormatter = DateFormatHelper("dd/mm/yyyy") |
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
4 changes: 2 additions & 2 deletions
4
...mmon/src/commonTest/kotlin/com/example/sqldelight/hockey/platform/DateFormatHelperTest.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
30 changes: 0 additions & 30 deletions
30
sample/common/src/iosMain/kotlin/com/example/sqldelight/hockey/data/Date.kt
This file was deleted.
Oops, something went wrong.
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
13 changes: 0 additions & 13 deletions
13
sample/common/src/jvmMain/kotlin/com/example/sqldelight/hockey/data/Date.kt
This file was deleted.
Oops, something went wrong.
10 changes: 8 additions & 2 deletions
10
sample/common/src/jvmMain/kotlin/com/example/sqldelight/hockey/platform/DateFormatHelper.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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package com.example.sqldelight.hockey.platform | ||
|
||
import com.example.sqldelight.hockey.data.Date | ||
import java.text.DateFormat | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
import kotlinx.datetime.LocalDate | ||
import kotlinx.datetime.TimeZone | ||
import kotlinx.datetime.atStartOfDayIn | ||
|
||
actual class DateFormatHelper actual constructor(format: String) { | ||
val dateFormatter = object : ThreadLocal<DateFormat>() { | ||
override fun initialValue(): DateFormat = SimpleDateFormat(format) | ||
} | ||
|
||
actual fun format(d: Date): String = dateFormatter.get()!!.format(d.time) | ||
actual fun format(d: LocalDate): String { | ||
val epochMilliseconds = d.atStartOfDayIn(TimeZone.currentSystemDefault()).toEpochMilliseconds() | ||
return dateFormatter.get()!!.format(Date(epochMilliseconds)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.