Skip to content

update: new datetime version #479

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

Merged
merged 3 commits into from
Jul 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,6 @@ such as properties and classes. Let's implement an expected property:
}
```

<!-- sample needs to be updated

> 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).
>
{style="tip"}

-->

## Run your application

You can run your multiplatform application for both [Android](#run-your-application-on-android)
Expand Down
32 changes: 13 additions & 19 deletions topics/multiplatform-onboard/multiplatform-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ function to display the number of days left until New Year's Day. The `kotlinx-d
multiplatform support, is the most convenient way to work with dates in your shared code.

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

```kotlin
kotlin {
//...
sourceSets {
commonMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:%dateTimeVersion%")
}
}
}
```
```kotlin
kotlin {
//...
sourceSets
languageSettings.optIn("kotlin.time.ExperimentalTime")
commonMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not change the variable's value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because not all samples have been updated to use 0.7.1 yet.

}
}
}
```

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

```kotlin
import kotlinx.datetime.*
import kotlin.time.Clock

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

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

<!-- sample needs to be updated

> 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).
>
{style="tip"}

-->

## Next step

In the next part of the tutorial, you'll add more dependencies and more complex logic to your project.
Expand Down
10 changes: 2 additions & 8 deletions topics/multiplatform-onboard/multiplatform-update-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Make some changes and see how they are reflected in the UI:
3. In the `Greeting.kt` file, update the `greet()` function:

```kotlin
import kotlin.random.Random

fun greet(): List<String> = buildList {
add(if (Random.nextBoolean()) "Hi!" else "Hello!")
add("Guess what this is! > ${platform.name.reversed()}!")
Expand Down Expand Up @@ -109,14 +111,6 @@ Implement the same changes as in the Android app:

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

<!-- sample needs to be updated

> 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).
>
{style="tip"}

-->

## Possible issues and solutions

### Xcode reports errors in the code calling the shared framework
Expand Down
9 changes: 6 additions & 3 deletions topics/multiplatform-onboard/multiplatform-upgrade-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ data class RocketLaunch (
6. Convert the launch date from UTC to your local date and format the output:

```kotlin
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.time.Instant

class RocketComponent {
// ...
Expand All @@ -234,7 +234,7 @@ data class RocketLaunch (
val date = Instant.parse(lastSuccessLaunch.launchDateUTC)
.toLocalDateTime(TimeZone.currentSystemDefault())

return "${date.month} ${date.dayOfMonth}, ${date.year}"
return "${date.month} ${date.day}, ${date.year}"
}
}
```
Expand Down Expand Up @@ -554,7 +554,10 @@ wrappers.
// ...
sourceSets{
all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
languageSettings {
optIn("kotlin.experimental.ExperimentalObjCName")
optIn("kotlin.time.ExperimentalTime")
}
}
// ...
}
Expand Down