Skip to content

Commit a7d51b7

Browse files
authored
update: new datetime version (#479)
1 parent 85e9e5d commit a7d51b7

File tree

4 files changed

+21
-38
lines changed

4 files changed

+21
-38
lines changed

topics/multiplatform-onboard/multiplatform-create-first-app.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,6 @@ such as properties and classes. Let's implement an expected property:
237237
}
238238
```
239239

240-
<!-- sample needs to be updated
241-
242-
> You can find this state of the project in our [GitHub repository](https://github.com/kotlin-hands-on/get-started-with-kmp/tree/main/step2).
243-
>
244-
{style="tip"}
245-
246-
-->
247-
248240
## Run your application
249241

250242
You can run your multiplatform application for both [Android](#run-your-application-on-android)

topics/multiplatform-onboard/multiplatform-dependencies.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ function to display the number of days left until New Year's Day. The `kotlinx-d
4949
multiplatform support, is the most convenient way to work with dates in your shared code.
5050

5151
1. Open the `build.gradle.kts` file located in the `shared` directory.
52-
2. Add the following dependency to the `commonMain` source set dependencies:
52+
2. Add the following dependency and the Kotlin time opt-in to the `commonMain` source set dependencies:
5353

54-
```kotlin
55-
kotlin {
56-
//...
57-
sourceSets {
58-
commonMain.dependencies {
59-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:%dateTimeVersion%")
60-
}
61-
}
62-
}
63-
```
54+
```kotlin
55+
kotlin {
56+
//...
57+
sourceSets
58+
languageSettings.optIn("kotlin.time.ExperimentalTime")
59+
commonMain.dependencies {
60+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
61+
}
62+
}
63+
}
64+
```
6465

6566
3. Click the **Sync Gradle Changes** button to synchronize Gradle files: ![Synchronize Gradle files](gradle-sync.png){width=50}
6667
4. In `shared/src/commonMain/kotlin`, create a new file, `NewYear.kt`, in the project directory where your `Greeting.kt` file is located.
@@ -69,6 +70,7 @@ multiplatform support, is the most convenient way to work with dates in your sha
6970

7071
```kotlin
7172
import kotlinx.datetime.*
73+
import kotlin.time.Clock
7274

7375
fun daysUntilNewYear(): Int {
7476
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
@@ -97,14 +99,6 @@ multiplatform support, is the most convenient way to work with dates in your sha
9799

98100
![Updated mobile multiplatform app with external dependencies](first-multiplatform-project-3.png){width=500}
99101

100-
<!-- sample needs to be updated
101-
102-
> You can find this state of the project in our [GitHub repository](https://github.com/kotlin-hands-on/get-started-with-kmp/tree/main/step4).
103-
>
104-
{style="tip"}
105-
106-
-->
107-
108102
## Next step
109103

110104
In the next part of the tutorial, you'll add more dependencies and more complex logic to your project.

topics/multiplatform-onboard/multiplatform-update-ui.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Make some changes and see how they are reflected in the UI:
3333
3. In the `Greeting.kt` file, update the `greet()` function:
3434

3535
```kotlin
36+
import kotlin.random.Random
37+
3638
fun greet(): List<String> = buildList {
3739
add(if (Random.nextBoolean()) "Hi!" else "Hello!")
3840
add("Guess what this is! > ${platform.name.reversed()}!")
@@ -109,14 +111,6 @@ Implement the same changes as in the Android app:
109111

110112
![Updated UI of your iOS multiplatform app](first-multiplatform-project-on-ios-2.png){width=300}
111113

112-
<!-- sample needs to be updated
113-
114-
> You can find this state of the project in our [GitHub repository](https://github.com/kotlin-hands-on/get-started-with-kmp/tree/main/step3).
115-
>
116-
{style="tip"}
117-
118-
-->
119-
120114
## Possible issues and solutions
121115

122116
### Xcode reports errors in the code calling the shared framework

topics/multiplatform-onboard/multiplatform-upgrade-app.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ data class RocketLaunch (
220220
6. Convert the launch date from UTC to your local date and format the output:
221221

222222
```kotlin
223-
import kotlinx.datetime.Instant
224223
import kotlinx.datetime.TimeZone
225224
import kotlinx.datetime.toLocalDateTime
225+
import kotlin.time.Instant
226226

227227
class RocketComponent {
228228
// ...
@@ -234,7 +234,7 @@ data class RocketLaunch (
234234
val date = Instant.parse(lastSuccessLaunch.launchDateUTC)
235235
.toLocalDateTime(TimeZone.currentSystemDefault())
236236

237-
return "${date.month} ${date.dayOfMonth}, ${date.year}"
237+
return "${date.month} ${date.day}, ${date.year}"
238238
}
239239
}
240240
```
@@ -554,7 +554,10 @@ wrappers.
554554
// ...
555555
sourceSets{
556556
all {
557-
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
557+
languageSettings {
558+
optIn("kotlin.experimental.ExperimentalObjCName")
559+
optIn("kotlin.time.ExperimentalTime")
560+
}
558561
}
559562
// ...
560563
}

0 commit comments

Comments
 (0)