Skip to content

Rename 'Clock.todayAt' to 'Clock.todayIn' #206

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 1 commit into from
May 23, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ by converting it to `LocalDateTime` and taking its `date` property.
val now: Instant = Clock.System.now()
val today: LocalDate = now.toLocalDateTime(TimeZone.currentSystemDefault()).date
// or more short
val today: LocalDate = Clock.System.todayAt(TimeZone.currentSystemDefault())
val today: LocalDate = Clock.System.todayIn(TimeZone.currentSystemDefault())
```
Note, that today's date really depends on the time zone in which you're observing the current moment.

Expand Down
7 changes: 5 additions & 2 deletions core/common/src/Clock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public interface Clock {
/**
* Returns the current date at the given [time zone][timeZone], according to [this Clock][this].
*/
public fun Clock.todayAt(timeZone: TimeZone): LocalDate =
now().toLocalDateTime(timeZone).date
public fun Clock.todayIn(timeZone: TimeZone): LocalDate =
now().toLocalDateTime(timeZone).date

/**
* Returns a [TimeSource] that uses this [Clock] to mark a time instant and to find the amount of time elapsed since that mark.
Expand All @@ -52,3 +52,6 @@ private class InstantTimeMark(private val instant: Instant, private val clock: C

override fun minus(duration: Duration): TimeMark = InstantTimeMark(instant - duration, clock)
}

@Deprecated("Use Clock.todayIn instead", ReplaceWith("this.todayIn(timeZone)"), DeprecationLevel.WARNING)
public fun Clock.todayAt(timeZone: TimeZone): LocalDate = todayIn(timeZone)
2 changes: 1 addition & 1 deletion core/common/test/LocalDateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LocalDateTest {
@Test
@Suppress("UNUSED_VARIABLE")
fun tomorrow() {
val today = Clock.System.todayAt(TimeZone.currentSystemDefault())
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())

val nextMonthPlusDay1 = today.plus(DateTimeUnit.MONTH).plus(1, DateTimeUnit.DAY)
val nextMonthPlusDay2 = today + DatePeriod(months = 1, days = 1)
Expand Down