Skip to content

Commit f5b4f38

Browse files
committed
Update the docs and samples
1 parent 3a491d2 commit f5b4f38

File tree

9 files changed

+50
-51
lines changed

9 files changed

+50
-51
lines changed

core/common/src/TimeZone.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public expect open class TimeZone {
130130
* Returns an instant that corresponds to this civil datetime value in the time zone provided as an implicit receiver.
131131
*
132132
* Note that the conversion is not always well-defined. There can be the following possible situations:
133-
* - Only one instant has this datetime value in the [timeZone].
133+
* - Only one instant has this datetime value in the time zone.
134134
* In this case, the conversion is unambiguous.
135-
* - No instant has this datetime value in the [timeZone].
135+
* - No instant has this datetime value in the time zone.
136136
* Such a situation appears when the time zone experiences a transition from a lesser to a greater offset.
137137
* In this case, the conversion is performed with the lesser (earlier) offset, as if the time gap didn't occur yet.
138-
* - Two possible instants can have these datetime components in the [timeZone].
138+
* - Two possible instants can have these datetime components in the time zone.
139139
* In this case, the earlier instant is returned.
140140
*
141141
* @see Instant.toLocalDateTime

core/common/test/samples/LocalDateSamples.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LocalDateSamples {
2424
// Parsing LocalDate values using predefined and custom formats
2525
check(LocalDate.parse("2024-04-16") == LocalDate(2024, Month.APRIL, 16))
2626
val customFormat = LocalDate.Format {
27-
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year()
27+
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year()
2828
}
2929
check(LocalDate.parse("Apr 16, 2024", customFormat) == LocalDate(2024, Month.APRIL, 16))
3030
}
@@ -42,7 +42,7 @@ class LocalDateSamples {
4242
fun customFormat() {
4343
// Parsing and formatting LocalDate values using a custom format
4444
val customFormat = LocalDate.Format {
45-
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year()
45+
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year()
4646
}
4747
val date = customFormat.parse("Apr 16, 2024")
4848
check(date == LocalDate(2024, Month.APRIL, 16))
@@ -55,9 +55,9 @@ class LocalDateSamples {
5555
// Constructing a LocalDate value using its constructor
5656
val date = LocalDate(2024, 4, 16)
5757
check(date.year == 2024)
58-
check(date.monthNumber == 4)
58+
check(date.month.number == 4)
5959
check(date.month == Month.APRIL)
60-
check(date.dayOfMonth == 16)
60+
check(date.day == 16)
6161
}
6262

6363
@Test
@@ -66,7 +66,7 @@ class LocalDateSamples {
6666
val date = LocalDate(2024, Month.APRIL, 16)
6767
check(date.year == 2024)
6868
check(date.month == Month.APRIL)
69-
check(date.dayOfMonth == 16)
69+
check(date.day == 16)
7070
}
7171

7272
@Test
@@ -86,10 +86,10 @@ class LocalDateSamples {
8686
}
8787

8888
@Test
89-
fun dayOfMonth() {
89+
fun day() {
9090
// Getting the day of the month
91-
for (dayOfMonth in 1..30) {
92-
check(LocalDate(2024, Month.APRIL, dayOfMonth).dayOfMonth == dayOfMonth)
91+
for (day in 1..30) {
92+
check(LocalDate(2024, Month.APRIL, day).day == day)
9393
}
9494
}
9595

@@ -140,7 +140,7 @@ class LocalDateSamples {
140140
check(LocalDate(2024, 4, 16).toString() == "2024-04-16")
141141
check(LocalDate(2024, 4, 16).format(LocalDate.Formats.ISO) == "2024-04-16")
142142
val customFormat = LocalDate.Format {
143-
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year()
143+
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year()
144144
}
145145
check(LocalDate(2024, 4, 16).format(customFormat) == "Apr 16, 2024")
146146
}

core/common/test/samples/LocalDateTimeSamples.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class LocalDateTimeSamples {
1414
@Test
1515
fun alternativeConstruction() {
1616
// Constructing a LocalDateTime value by specifying its components
17-
val dateTime1 = LocalDateTime(year = 2021, monthNumber = 3, dayOfMonth = 27, hour = 2, minute = 16, second = 20)
17+
val dateTime1 = LocalDateTime(year = 2021, month = 3, day = 27, hour = 2, minute = 16, second = 20)
1818
val dateTime2 = LocalDateTime(
19-
year = 2021, month = Month.MARCH, dayOfMonth = 27,
19+
year = 2021, month = Month.MARCH, day = 27,
2020
hour = 2, minute = 16, second = 20, nanosecond = 0
2121
)
2222
check(dateTime1 == dateTime2)
@@ -71,21 +71,21 @@ class LocalDateTimeSamples {
7171
// Constructing a LocalDateTime value using its constructor
7272
val dateTime = LocalDateTime(
7373
year = 2024,
74-
monthNumber = 2,
75-
dayOfMonth = 15,
74+
month = 2,
75+
day = 15,
7676
hour = 16,
7777
minute = 48,
7878
second = 59,
79-
nanosecond = 999_999_999,
79+
nanosecond = 999_999_999
8080
)
8181
check(dateTime.date == LocalDate(2024, 2, 15))
8282
check(dateTime.time == LocalTime(16, 48, 59, 999_999_999))
8383
val dateTimeWithoutSeconds = LocalDateTime(
8484
year = 2024,
85-
monthNumber = 2,
86-
dayOfMonth = 15,
85+
month = 2,
86+
day = 15,
8787
hour = 16,
88-
minute = 48,
88+
minute = 48
8989
)
9090
check(dateTimeWithoutSeconds.date == LocalDate(2024, 2, 15))
9191
check(dateTimeWithoutSeconds.time == LocalTime(16, 48))
@@ -97,20 +97,20 @@ class LocalDateTimeSamples {
9797
val dateTime = LocalDateTime(
9898
year = 2024,
9999
month = Month.FEBRUARY,
100-
dayOfMonth = 15,
100+
day = 15,
101101
hour = 16,
102102
minute = 48,
103103
second = 59,
104-
nanosecond = 999_999_999,
104+
nanosecond = 999_999_999
105105
)
106106
check(dateTime.date == LocalDate(2024, Month.FEBRUARY, 15))
107107
check(dateTime.time == LocalTime(16, 48, 59, 999_999_999))
108108
val dateTimeWithoutSeconds = LocalDateTime(
109109
year = 2024,
110110
month = Month.FEBRUARY,
111-
dayOfMonth = 15,
111+
day = 15,
112112
hour = 16,
113-
minute = 48,
113+
minute = 48
114114
)
115115
check(dateTimeWithoutSeconds.date == LocalDate(2024, Month.FEBRUARY, 15))
116116
check(dateTimeWithoutSeconds.time == LocalTime(16, 48))
@@ -136,8 +136,7 @@ class LocalDateTimeSamples {
136136
val dateTime = LocalDateTime(date, time)
137137
check(dateTime.year == dateTime.date.year)
138138
check(dateTime.month == dateTime.date.month)
139-
check(dateTime.monthNumber == dateTime.date.monthNumber)
140-
check(dateTime.dayOfMonth == dateTime.date.dayOfMonth)
139+
check(dateTime.day == dateTime.date.day)
141140
check(dateTime.dayOfWeek == dateTime.date.dayOfWeek)
142141
check(dateTime.dayOfYear == dateTime.date.dayOfYear)
143142
}

core/common/test/samples/LocalTimeSamples.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class LocalTimeSamples {
242242
val firstMorningOfEveryMonth = (1..12).map { month ->
243243
morning.atDate(2021, month, 1)
244244
}
245-
check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 })
245+
check(firstMorningOfEveryMonth.all { it.time == morning && it.day == 1 })
246246
}
247247

248248
/**
@@ -255,7 +255,7 @@ class LocalTimeSamples {
255255
val firstMorningOfEveryMonth = Month.entries.map { month ->
256256
morning.atDate(2021, month, 1)
257257
}
258-
check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 })
258+
check(firstMorningOfEveryMonth.all { it.time == morning && it.day == 1 })
259259
}
260260

261261
@Test

core/common/test/samples/format/DateTimeComponentsSamples.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ class DateTimeComponentsSamples {
167167
fun date() {
168168
// Formatting and parsing a date in complex scenarios
169169
val format = DateTimeComponents.Format {
170-
year(); char('-'); monthNumber(); char('-'); dayOfMonth()
170+
year(); char('-'); monthNumber(); char('-'); day()
171171
}
172172
val formattedDate = format.format {
173173
setDate(LocalDate(2023, 1, 2))
174174
check(year == 2023)
175175
check(month == Month.JANUARY)
176-
check(dayOfMonth == 2)
176+
check(day == 2)
177177
check(dayOfWeek == DayOfWeek.MONDAY)
178178
check(dayOfYear == 2)
179179
}
@@ -182,7 +182,7 @@ class DateTimeComponentsSamples {
182182
check(parsedDate.toLocalDate() == LocalDate(2023, 1, 2))
183183
check(parsedDate.year == 2023)
184184
check(parsedDate.month == Month.JANUARY)
185-
check(parsedDate.dayOfMonth == 2)
185+
check(parsedDate.day == 2)
186186
check(parsedDate.dayOfWeek == null)
187187
check(parsedDate.dayOfYear == null)
188188
}

core/common/test/samples/format/DateTimeFormatBuilderSamples.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DateTimeFormatBuilderSamples {
1717
val format = LocalDate.Format {
1818
monthNumber()
1919
char('/')
20-
dayOfMonth()
20+
day()
2121
chars(", ")
2222
year()
2323
}
@@ -96,7 +96,7 @@ class DateTimeFormatBuilderSamples {
9696
char('-')
9797
monthNumber()
9898
char('-')
99-
dayOfMonth()
99+
day()
100100
}
101101
check(LocalDate(2020, 1, 1).format(format) == "2020-01-01")
102102
}

core/common/test/samples/format/DateTimeFormatSamples.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DateTimeFormatSamples {
4343
// the input string is in the expected format, but the value is invalid
4444
}
4545
// to parse strings that have valid formats but invalid values, use `DateTimeComponents`:
46-
check(DateTimeComponents.Format { date(LocalDate.Formats.ISO) }.parse("2021-02-40").dayOfMonth == 40)
46+
check(DateTimeComponents.Format { date(LocalDate.Formats.ISO) }.parse("2021-02-40").day == 40)
4747
}
4848

4949
@Test
@@ -55,7 +55,7 @@ class DateTimeFormatSamples {
5555
check(LocalDate.Formats.ISO.parseOrNull("2021-02-40") == null)
5656
// to parse strings that have valid formats but invalid values, use `DateTimeComponents`:
5757
val dateTimeComponentsFormat = DateTimeComponents.Format { date(LocalDate.Formats.ISO) }
58-
check(dateTimeComponentsFormat.parseOrNull("2021-02-40")?.dayOfMonth == 40)
58+
check(dateTimeComponentsFormat.parseOrNull("2021-02-40")?.day == 40)
5959
}
6060

6161
@Test
@@ -86,7 +86,7 @@ class DateTimeFormatSamples {
8686
chars(", ")
8787
monthNumber(Padding.NONE)
8888
char('/')
89-
dayOfMonth(Padding.ZERO)
89+
day(Padding.ZERO)
9090
}
9191
val leoFirstReignStart = LocalDate(457, 2, 7)
9292
check(leoFirstReignStart.format(format) == " 457, 2/07")
@@ -98,7 +98,7 @@ class DateTimeFormatSamples {
9898
val format = LocalDate.Format {
9999
monthNumber(Padding.ZERO) // padding with zeros is the default, but can be explicitly specified
100100
char('/')
101-
dayOfMonth()
101+
day()
102102
char(' ')
103103
year()
104104
}
@@ -119,7 +119,7 @@ class DateTimeFormatSamples {
119119
val format = LocalDate.Format {
120120
monthNumber(Padding.NONE)
121121
char('/')
122-
dayOfMonth()
122+
day()
123123
char(' ')
124124
year()
125125
}
@@ -136,7 +136,7 @@ class DateTimeFormatSamples {
136136
val format = LocalDate.Format {
137137
monthNumber(Padding.SPACE)
138138
char('/')
139-
dayOfMonth()
139+
day()
140140
char(' ')
141141
year()
142142
}

core/common/test/samples/format/LocalDateFormatSamples.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocalDateFormatSamples {
1515
fun year() {
1616
// Using the year number in a custom format
1717
val format = LocalDate.Format {
18-
year(); char(' '); monthNumber(); char('/'); dayOfMonth()
18+
year(); char(' '); monthNumber(); char('/'); day()
1919
}
2020
check(format.format(LocalDate(2021, 1, 13)) == "2021 01/13")
2121
check(format.format(LocalDate(13, 1, 13)) == "0013 01/13")
@@ -27,7 +27,7 @@ class LocalDateFormatSamples {
2727
fun yearTwoDigits() {
2828
// Using two-digit years in a custom format
2929
val format = LocalDate.Format {
30-
yearTwoDigits(baseYear = 1960); char(' '); monthNumber(); char('/'); dayOfMonth()
30+
yearTwoDigits(baseYear = 1960); char(' '); monthNumber(); char('/'); day()
3131
}
3232
check(format.format(LocalDate(1960, 1, 13)) == "60 01/13")
3333
check(format.format(LocalDate(2000, 1, 13)) == "00 01/13")
@@ -41,12 +41,12 @@ class LocalDateFormatSamples {
4141
fun monthNumber() {
4242
// Using month number with various paddings in a custom format
4343
val zeroPaddedMonths = LocalDate.Format {
44-
monthNumber(); char('/'); dayOfMonth(); char('/'); year()
44+
monthNumber(); char('/'); day(); char('/'); year()
4545
}
4646
check(zeroPaddedMonths.format(LocalDate(2021, 1, 13)) == "01/13/2021")
4747
check(zeroPaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021")
4848
val spacePaddedMonths = LocalDate.Format {
49-
monthNumber(padding = Padding.SPACE); char('/'); dayOfMonth(); char('/'); year()
49+
monthNumber(padding = Padding.SPACE); char('/'); day(); char('/'); year()
5050
}
5151
check(spacePaddedMonths.format(LocalDate(2021, 1, 13)) == " 1/13/2021")
5252
check(spacePaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021")
@@ -56,7 +56,7 @@ class LocalDateFormatSamples {
5656
fun monthName() {
5757
// Using strings for month names in a custom format
5858
val format = LocalDate.Format {
59-
monthName(MonthNames.ENGLISH_FULL); char(' '); dayOfMonth(); char('/'); year()
59+
monthName(MonthNames.ENGLISH_FULL); char(' '); day(); char('/'); year()
6060
}
6161
check(format.format(LocalDate(2021, 1, 13)) == "January 13/2021")
6262
check(format.format(LocalDate(2021, 12, 13)) == "December 13/2021")
@@ -66,12 +66,12 @@ class LocalDateFormatSamples {
6666
fun dayOfMonth() {
6767
// Using day-of-month with various paddings in a custom format
6868
val zeroPaddedDays = LocalDate.Format {
69-
dayOfMonth(); char('/'); monthNumber(); char('/'); year()
69+
day(); char('/'); monthNumber(); char('/'); year()
7070
}
7171
check(zeroPaddedDays.format(LocalDate(2021, 1, 6)) == "06/01/2021")
7272
check(zeroPaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021")
7373
val spacePaddedDays = LocalDate.Format {
74-
dayOfMonth(padding = Padding.SPACE); char('/'); monthNumber(); char('/'); year()
74+
day(padding = Padding.SPACE); char('/'); monthNumber(); char('/'); year()
7575
}
7676
check(spacePaddedDays.format(LocalDate(2021, 1, 6)) == " 6/01/2021")
7777
check(spacePaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021")
@@ -81,7 +81,7 @@ class LocalDateFormatSamples {
8181
fun dayOfWeek() {
8282
// Using strings for day-of-week names in a custom format
8383
val format = LocalDate.Format {
84-
dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); char('/'); monthNumber(); char('/'); year()
84+
dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED); char(' '); day(); char('/'); monthNumber(); char('/'); year()
8585
}
8686
check(format.format(LocalDate(2021, 1, 13)) == "Wed 13/01/2021")
8787
check(format.format(LocalDate(2021, 12, 13)) == "Mon 13/12/2021")
@@ -115,7 +115,7 @@ class LocalDateFormatSamples {
115115
val format = LocalDate.Format {
116116
monthName(MonthNames.ENGLISH_ABBREVIATED) // "Jan", "Feb", ...
117117
char(' ')
118-
dayOfMonth()
118+
day()
119119
chars(", ")
120120
year()
121121
}
@@ -159,7 +159,7 @@ class LocalDateFormatSamples {
159159
val format = LocalDate.Format {
160160
monthName(MonthNames.ENGLISH_FULL)
161161
char(' ')
162-
dayOfMonth()
162+
day()
163163
chars(", ")
164164
year()
165165
}
@@ -172,7 +172,7 @@ class LocalDateFormatSamples {
172172
val format = LocalDate.Format {
173173
monthName(MonthNames.ENGLISH_ABBREVIATED)
174174
char(' ')
175-
dayOfMonth()
175+
day()
176176
chars(", ")
177177
year()
178178
}

core/commonKotlin/src/internal/MonthDayTime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal fun JulianDayOfYearSkippingLeapDate(dayOfYear: Int) : DateOfYear {
5353
// For example, `dayOfYear = 60` is always 1st March, even in leap years.
5454
// We take a non-leap year, as in that case, this is the same as JulianDayOfYear, so regular addition works.
5555
val date = LocalDate(2011, 1, 1).plusDays(dayOfYear - 1)
56-
return MonthDayOfYear(date.month, MonthDayOfYear.TransitionDay.ExactlyDayOfMonth(date.dayOfMonth))
56+
return MonthDayOfYear(date.month, MonthDayOfYear.TransitionDay.ExactlyDayOfMonth(date.day))
5757
}
5858

5959
internal class MonthDayOfYear(val month: Month, val day: TransitionDay) : DateOfYear {

0 commit comments

Comments
 (0)