Skip to content
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

docs: fix typos in README.md #328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@

A multiplatform Kotlin library for working with date and time.

See [Using in your projects](#using-in-your-projects) for the instructions how to setup a dependency in your project.
See [Using in your projects](#using-in-your-projects) for the instructions on how to set up a dependency in your project.

## Design overview

There are a few guiding principles in the design of `kotlinx-datetime`. First of all, it is pragmatic, focused
There are a few guiding principles in the design of `kotlinx-datetime`. First of all, it is pragmatic and focused
on the most common problems developers face every day (pun intended) when working with dates and times. It is not
all-encompassing and lacks some domain-specific utilities that special-purpose applications might need.
We chose convenience over generality, so the API surface this library provides is as minimal as possible
to meet the use-cases.
to meet the use cases.

The library puts a clear boundary between the physical time of an instant and the local, time-zone dependent
The library puts a clear boundary between the physical time of an instant and the local, time-zone-dependent
civil time, consisting of components such as year, month, etc that people use when talking about time.
We intentionally avoid entities in the library that mix both together and could be misused.
However, there are convenience operations that take, for example, a physical instant and perform a calendar-based
adjustment (such as adding a month); all such operations
explicitly take a time-zone information as parameter to clearly state that their result depends on the civil time-zone
explicitly take time-zone information as a parameter to clearly state that their result depends on the civil time zone
rules which are subject to change at any time.

The library is based on the ISO 8601 international standard, other ways to represent dates and times are out of
its scope. Internationalization (such as locale-specific month and day names) is out the scope, too.
its scope. Internationalization (such as locale-specific month and day names) is out of the scope, too.

## Types

Expand Down Expand Up @@ -59,7 +59,7 @@ Here is some basic advice on how to choose which of the date-carrying types to u

- Use `LocalDateTime` to represent a time of the event that is scheduled to happen in the far future at a certain
local time (like a scheduled meeting in a few months from now). You'll have to keep track of the `TimeZone` of
the scheduled event separately. Try to avoid converting future events to `Instant` in advance, because time-zone
the scheduled event separately. Try to avoid converting future events to `Instant` in advance, because time zone
rules might change unexpectedly in the future. In this [blog post](https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a-silver-bullet/), you can read more about why it's not always
a good idea to use `Instant` everywhere.

Expand All @@ -71,7 +71,7 @@ Here is some basic advice on how to choose which of the date-carrying types to u

## Operations

With the above types you can get the following operations done.
With the above types, you can get the following operations done.


### Getting the current moment of time
Expand All @@ -95,7 +95,7 @@ val currentMoment = Clock.System.now()

### Converting an instant to local date and time components

An `Instant` is just a counter of high resolution time intervals since the beginning of time scale.
An `Instant` is just a counter of high-resolution time intervals since the beginning of the time scale.
To get human readable components from an `Instant` value, you need to convert it to the `LocalDateTime`
type that represents date and time components without a reference to the particular time zone.

Expand Down Expand Up @@ -152,31 +152,31 @@ val knownDate = LocalDate(2020, 2, 21)

### Getting local time components

A `LocalTime` represents local time without date. You can obtain one from an `Instant`
A `LocalTime` represents local time without a date. You can obtain one from an `Instant`
by converting it to `LocalDateTime` and taking its `time` property.

```kotlin
val now: Instant = Clock.System.now()
val thisTime: LocalTime = now.toLocalDateTime(TimeZone.currentSystemDefault()).time
```

A `LocalTime` can be constructed from four components, hour, minute, second and nanosecond:
A `LocalTime` can be constructed from four components, hour, minute, second, and nanosecond:
```kotlin
val knownTime = LocalTime(hour = 23, minute = 59, second = 12)
val timeWithNanos = LocalTime(hour = 23, minute = 59, second = 12, nanosecond = 999)
val hourMinute = LocalTime(hour = 12, minute = 13)
```

### Converting instant to and from unix time
### Converting instant to and from Unix time

An `Instant` can be converted to a number of milliseconds since the Unix/POSIX epoch with the `toEpochMilliseconds()` function.
To convert back, use the companion object function `Instant.fromEpochMilliseconds(Long)`.

### Converting instant and local date/time to and from string

Currently, `Instant`, `LocalDateTime`, `LocalDate` and `LocalTime` only support ISO-8601 format.
Currently, `Instant`, `LocalDateTime`, `LocalDate`, and `LocalTime` only support ISO-8601 format.
The `toString()` function is used to convert the value to a string in that format, and
the `parse` function in companion object is used to parse a string representation back.
the `parse` function in the companion object is used to parse a string representation back.


```kotlin
Expand All @@ -188,11 +188,11 @@ val instantBefore = Instant.parse("2010-06-01T22:19:44.475Z")
Alternatively, the `String.to...()` extension functions can be used instead of `parse`,
where it feels more convenient:

`LocalDateTime` uses a similar format, but without `Z` UTC time zone designator in the end.
`LocalDateTime` uses a similar format, but without `Z` UTC time zone designator at the end.

`LocalDate` uses a format with just year, month, and date components, e.g. `2010-06-01`.

`LocalTime` uses a format with just hour, minute, second and (if non-zero) nanosecond components, e.g. `12:01:03`.
`LocalTime` uses a format with just hour, minute, second, and (if non-zero) nanosecond components, e.g. `12:01:03`.

```kotlin
"2010-06-01T22:19:44.475Z".toInstant()
Expand Down Expand Up @@ -240,7 +240,7 @@ val threeYearsAndAMonthLater = now.plus(DateTimePeriod(years = 3, months = 1), s
```

Note that `plus` and `...until` operations require a `TimeZone` as a parameter because the calendar interval between
two particular instants can be different, when calculated in different time zones.
two particular instants can be different when calculated in different time zones.

### Date arithmetic

Expand All @@ -253,7 +253,7 @@ Similar operations with date units are provided for `LocalDate` type:

Notice that, instead of the general `DateTimeUnit` and `DateTimePeriod` types, we're using their subtypes
`DateTimeUnit.DateBased` and `DatePeriod` respectively. This allows preventing the situations when
time components are being added to a date at compile time.
time components are being added to date at compile time.
Copy link
Member

Choose a reason for hiding this comment

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

"a date" here means "an instance of LocalDate type"


### Date + time arithmetic

Expand Down Expand Up @@ -284,7 +284,7 @@ val localDateTimeTwoDaysLater = instantTwoDaysLater.toLocalDateTime(timeZone)

## Implementation

The implementation of date/time types, such as `Instant`, `LocalDateTime`, `TimeZone` and so on, relies on:
The implementation of date/time types, such as `Instant`, `LocalDateTime`, `TimeZone`, and so on, relies on:

- in JVM: [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) API;
- in Js and Wasm-Js: [`js-joda`](https://js-joda.github.io/js-joda/) library;
Expand Down Expand Up @@ -318,7 +318,7 @@ repositories {
}
```

- In multiplatform projects, add a dependency to the commonMain source set dependencies
- In multiplatform projects, add a dependency to the `commonMain` source set of dependencies
Copy link
Member

Choose a reason for hiding this comment

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

It's the dependencies DSL block of a source set, not a set of dependencies.

```kotlin
kotlin {
sourceSets {
Expand All @@ -343,7 +343,7 @@ dependencies {

By default, there's only one time zone available in Kotlin/JS: the `SYSTEM` time zone with a fixed offset.

If you want to use all time zones in Kotlin/JS platform, you need to add the following npm dependency:
If you want to use all time zones in the Kotlin/JS platform, you need to add the following npm dependency:

```kotlin
kotlin {
Expand All @@ -357,7 +357,7 @@ kotlin {
}
```

and after that add the following initialization code in your project:
and after that add the following initialization code to your project:

```kotlin
@JsModule("@js-joda/timezone")
Expand Down Expand Up @@ -391,7 +391,7 @@ git submodule update
```

The project requires JDK 8 to build classes and to run tests.
Gradle will try to find it among the installed JDKs or [provision](https://docs.gradle.org/current/userguide/toolchains.html#sec:provisioning) it automatically if it couldn't be found.
Gradle will try to find it among the installed JDKs or [provision](https://docs.gradle.org/current/userguide/toolchains.html#sec:provisioning) automatically if it can't be found.
Copy link
Member

Choose a reason for hiding this comment

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

Better to reword as "[download] it automatically"

The path to JDK 8 can be additionally specified with the environment variable `JDK_8`.
For local builds, you can use a later version of JDK if you don't have that
version installed. Specify the version of this JDK with the `java.mainToolchainVersion` Gradle property.
Expand Down