@@ -21,11 +21,11 @@ all-encompassing and lacks some domain-specific utilities that special-purpose a
21
21
We chose convenience over generality, so the API surface this library provides is as minimal as possible
22
22
to meet the use-cases.
23
23
24
- The library puts a clear boundary between physical time of an instant and a local, time-zone dependent civil time,
25
- consisting of components such as year, month, etc that people use when talking about time.
24
+ The library puts a clear boundary between the physical time of an instant and the local, time-zone dependent
25
+ civil time, consisting of components such as year, month, etc that people use when talking about time.
26
26
We intentionally avoid entities in the library that mix both together and could be misused.
27
27
However, there are convenience operations that take, for example, a physical instant and perform a calendar-based
28
- adjustment (such as adding a month); all such operation
28
+ adjustment (such as adding a month); all such operations
29
29
explicitly take a time-zone information as parameter to clearly state that their result depends on the civil time-zone
30
30
rules which are subject to change at any time.
31
31
@@ -34,7 +34,7 @@ its scope. Internationalization (such as locale-specific month and day names) is
34
34
35
35
## Types
36
36
37
- The library provides the basic set of types for working with date and time:
37
+ The library provides a basic set of types for working with date and time:
38
38
39
39
- ` Instant ` to represent a moment on the UTC-SLS time scale;
40
40
- ` Clock ` to obtain the current instant;
@@ -65,9 +65,9 @@ Here is some basic advice on how to choose which of the date-carrying types to u
65
65
66
66
Also, use ` LocalDateTime ` to decode an ` Instant ` to its local date-time components for display and UIs.
67
67
68
- - Use ` LocalDate ` to represent a date of the event that does not have a specific time associated with it (like a birth date).
68
+ - Use ` LocalDate ` to represent the date of an event that does not have a specific time associated with it (like a birth date).
69
69
70
- - Use ` LocalTime ` to represent a time of the event that does not have a specific date associated with it.
70
+ - Use ` LocalTime ` to represent the time of an event that does not have a specific date associated with it.
71
71
72
72
## Operations
73
73
@@ -95,9 +95,9 @@ val currentMoment = Clock.System.now()
95
95
96
96
### Converting an instant to local date and time components
97
97
98
- ` Instant ` is just a counter of high resolution time intervals since the beginning of time scale.
99
- To get human readable components from an ` Instant ` value you need to convert it to ` LocalDateTime ` type
100
- that represents date and time components without a reference to the particular time zone.
98
+ An ` Instant ` is just a counter of high resolution time intervals since the beginning of time scale.
99
+ To get human readable components from an ` Instant ` value, you need to convert it to the ` LocalDateTime `
100
+ type that represents date and time components without a reference to the particular time zone.
101
101
102
102
The ` TimeZone ` type provides the rules to convert instants from and to date/time components.
103
103
@@ -107,7 +107,7 @@ val datetimeInUtc: LocalDateTime = currentMoment.toLocalDateTime(TimeZone.UTC)
107
107
val datetimeInSystemZone: LocalDateTime = currentMoment.toLocalDateTime(TimeZone .currentSystemDefault())
108
108
```
109
109
110
- ` LocalDateTime ` instance exposes familiar components of the Gregorian calendar:
110
+ A ` LocalDateTime ` instance exposes familiar components of the Gregorian calendar:
111
111
` year ` , ` month ` , ` dayOfMonth ` , ` hour ` , and so on up to ` nanosecond ` .
112
112
The property ` dayOfWeek ` shows what weekday that date is,
113
113
and ` dayOfYear ` shows the day number since the beginning of a year.
@@ -119,7 +119,7 @@ val tzBerlin = TimeZone.of("Europe/Berlin")
119
119
val datetimeInBerlin = currentMoment.toLocalDateTime(tzBerlin)
120
120
```
121
121
122
- ` LocalDateTime ` instance can be constructed from individual components:
122
+ A ` LocalDateTime ` instance can be constructed from individual components:
123
123
124
124
``` kotlin
125
125
val kotlinReleaseDateTime = LocalDateTime (2016 , 2 , 15 , 16 , 57 , 0 , 0 )
@@ -134,7 +134,7 @@ val kotlinReleaseInstant = kotlinReleaseDateTime.toInstant(TimeZone.of("UTC+3"))
134
134
135
135
### Getting local date components
136
136
137
- ` LocalDate ` type represents local date without time. You can obtain it from ` Instant `
137
+ A ` LocalDate ` represents a local date without time. You can obtain one from an ` Instant `
138
138
by converting it to ` LocalDateTime ` and taking its ` date ` property.
139
139
140
140
``` kotlin
@@ -152,15 +152,15 @@ val knownDate = LocalDate(2020, 2, 21)
152
152
153
153
### Getting local time components
154
154
155
- ` LocalTime ` type represents local time without date. You can obtain it from ` Instant `
155
+ A ` LocalTime ` represents local time without date. You can obtain one from an ` Instant `
156
156
by converting it to ` LocalDateTime ` and taking its ` time ` property.
157
157
158
158
``` kotlin
159
159
val now: Instant = Clock .System .now()
160
160
val thisTime: LocalTime = now.toLocalDateTime(TimeZone .currentSystemDefault()).time
161
161
```
162
162
163
- ` LocalTime ` can be constructed from four components, hour, minute, second and nanosecond:
163
+ A ` LocalTime ` can be constructed from four components, hour, minute, second and nanosecond:
164
164
``` kotlin
165
165
val knownTime = LocalTime (hour = 23 , minute = 59 , second = 12 )
166
166
val timeWithNanos = LocalTime (hour = 23 , minute = 59 , second = 12 , nanosecond = 999 )
@@ -170,7 +170,7 @@ val hourMinute = LocalTime(hour = 12, minute = 13)
170
170
### Converting instant to and from unix time
171
171
172
172
An ` Instant ` can be converted to a number of milliseconds since the Unix/POSIX epoch with the ` toEpochMilliseconds() ` function.
173
- To convert back, use ` Instant.fromEpochMilliseconds(Long) ` companion object function .
173
+ To convert back, use the companion object function ` Instant.fromEpochMilliseconds(Long) ` .
174
174
175
175
### Converting instant and local date/time to and from string
176
176
@@ -185,14 +185,14 @@ instantNow.toString() // returns something like 2015-12-31T12:30:00Z
185
185
val instantBefore = Instant .parse(" 2010-06-01T22:19:44.475Z" )
186
186
```
187
187
188
- Alternatively, ` String.to...() ` extension functions can be used instead of ` parse ` ,
188
+ Alternatively, the ` String.to...() ` extension functions can be used instead of ` parse ` ,
189
189
where it feels more convenient:
190
190
191
- ` LocalDateTime ` uses the similar format, but without ` Z ` UTC time zone designator in the end.
191
+ ` LocalDateTime ` uses a similar format, but without ` Z ` UTC time zone designator in the end.
192
192
193
- ` LocalDate ` uses format with just year, month, and date components, e.g. ` 2010-06-01 ` .
193
+ ` LocalDate ` uses a format with just year, month, and date components, e.g. ` 2010-06-01 ` .
194
194
195
- ` LocalTime ` uses format with just hour, minute, second and (if non-zero) nanosecond components, e.g. ` 12:01:03 ` .
195
+ ` LocalTime ` uses a format with just hour, minute, second and (if non-zero) nanosecond components, e.g. ` 12:01:03 ` .
196
196
197
197
``` kotlin
198
198
" 2010-06-01T22:19:44.475Z" .toInstant()
@@ -214,13 +214,13 @@ val equidistantInstantInTheFuture: Instant = now + durationSinceThen
214
214
` Duration ` is a type from the experimental ` kotlin.time ` package in the Kotlin standard library.
215
215
This type holds the amount of time that can be represented in different time units: from nanoseconds to 24H days.
216
216
217
- To get the calendar difference between two instants you can use ` Instant.periodUntil(Instant, TimeZone) ` function.
217
+ To get the calendar difference between two instants you can use the ` Instant.periodUntil(Instant, TimeZone) ` function.
218
218
219
219
``` kotlin
220
220
val period: DateTimePeriod = instantInThePast.periodUntil(Clock .System .now(), TimeZone .UTC )
221
221
```
222
222
223
- ` DateTimePeriod ` represents a difference between two particular moments as a sum of calendar components,
223
+ A ` DateTimePeriod ` represents a difference between two particular moments as a sum of calendar components,
224
224
like "2 years, 3 months, 10 days, and 22 hours".
225
225
226
226
The difference can be calculated as an integer amount of specified date or time units:
@@ -239,19 +239,19 @@ val tomorrow = now.plus(2, DateTimeUnit.DAY, systemTZ)
239
239
val threeYearsAndAMonthLater = now.plus(DateTimePeriod (years = 3 , months = 1 ), systemTZ)
240
240
```
241
241
242
- Note that ` plus ` and ` ...until ` operations require ` TimeZone ` as a parameter because the calendar interval between
242
+ Note that ` plus ` and ` ...until ` operations require a ` TimeZone ` as a parameter because the calendar interval between
243
243
two particular instants can be different, when calculated in different time zones.
244
244
245
245
### Date arithmetic
246
246
247
- The similar operations with date units are provided for ` LocalDate ` type:
247
+ Similar operations with date units are provided for ` LocalDate ` type:
248
248
249
249
- ` LocalDate.plus(number, DateTimeUnit.DateBased) `
250
250
- ` LocalDate.plus(DatePeriod) `
251
251
- ` LocalDate.until(LocalDate, DateTimeUnit.DateBased) ` and the shortcuts ` yearsUntil ` , ` monthUntil ` , ` daysUntil `
252
252
- ` LocalDate.periodUntil(LocalDate): DatePeriod ` and ` LocalDate.minus(LocalDate): DatePeriod `
253
253
254
- Notice that instead of general ` DateTimeUnit ` and ` DateTimePeriod ` we're using their subtypes
254
+ Notice that, instead of the general ` DateTimeUnit ` and ` DateTimePeriod ` types, we're using their subtypes
255
255
` DateTimeUnit.DateBased ` and ` DatePeriod ` respectively. This allows preventing the situations when
256
256
time components are being added to a date at compile time.
257
257
@@ -288,7 +288,7 @@ The implementation of date/time types, such as `Instant`, `LocalDateTime`, `Time
288
288
289
289
- in JVM: [ ` java.time ` ] ( https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html ) API;
290
290
- in JS: [ ` js-joda ` ] ( https://js-joda.github.io/js-joda/ ) library;
291
- - in Native: based on [ ThreeTen backport project] ( https://www.threeten.org/threetenbp/ )
291
+ - in Native: based on the [ ThreeTen backport project] ( https://www.threeten.org/threetenbp/ )
292
292
- time zone support is provided by [ date] ( https://github.com/HowardHinnant/date/ ) C++ library;
293
293
294
294
## Known/open issues, work TBD
0 commit comments