Skip to content

Commit 580b5cc

Browse files
committed
Update README
1 parent fbc83d0 commit 580b5cc

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,33 @@
55
<img src="https://github.com/kean/Nuke/workflows/NaiveDate%20CI/badge.svg">
66
</p>
77

8-
`Date` type is great for working with time zones (e.g. `2017-09-29T15:00:00+0300`), however, there are scenarios in which **naive** dates and times are desirable.
8+
Native `Date` type is great for working with time zones (e.g. `2017-09-29T15:00:00+0300`), but there are scenarios where you don't know or care about the time zone. These types of dates are often called **naive**.
99

1010

1111
## Usage
1212

13-
The library implements three types:
14-
- `NaiveDate` (e.g. `2017-09-29`)
13+
The `NaiveDate` library implements three types:
14+
15+
- `NaiveDate` (e.g. `2021-09-29`)
1516
- `NaiveTime` (e.g. `15:30:00`)
16-
- `NaiveDateTime` (e.g. `2017-09-29T15:30:00` - no time zone and no offset).
17+
- `NaiveDateTime` (e.g. `2021-09-29T15:30:00` - no time zone and no offset).
1718

18-
Each of them implements `Equatable`, `Comparable`, `LosslessStringConvertible`, `Codable` protocols. Naive types can also be converted to `Date`, and `DateComponents`.
19+
They all implement `Equatable`, `Comparable`, `LosslessStringConvertible`, and `Codable` protocols. Naive date types can also be converted to `Date`, and `DateComponents`.
1920

2021
### Create
2122

22-
Naive dates and times can be created from a string (using a predefined format), using `Decodable`, or with a memberwise initializer:
23+
Naive dates and times can be created from a string (using a predefined format[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6), using `Decodable`, or with a memberwise initializer:
2324

2425
```swift
25-
NaiveDate("2017-10-01")
26-
NaiveDate(year: 2017, month: 10, day: 1)
26+
NaiveDate("2021-10-01")
27+
NaiveDate(year: 2021, month: 10, day: 1)
2728

2829
NaiveTime("15:30:00")
2930
NaiveTime(hour: 15, minute: 30, second: 0)
3031

31-
NaiveDateTime("2017-10-01T15:30")
32+
NaiveDateTime("2021-10-01T15:30")
3233
NaiveDateTime(
33-
date: NaiveDate(year: 2017, month: 10, day: 1),
34+
date: NaiveDate(year: 2021, month: 10, day: 1),
3435
time: NaiveTime(hour: 15, minute: 30, second: 0)
3536
)
3637
```
@@ -40,39 +41,39 @@ NaiveDateTime(
4041
Format dates without having to worry about time zones:
4142

4243
```swift
43-
let date = NaiveDate("2017-11-01")!
44+
let date = NaiveDate("2021-11-01")!
4445
NaiveDateFormatter(dateStyle: .short).string(from: date)
45-
// prints "Nov 1, 2017"
46+
// prints "Nov 1, 2021"
4647

4748
let time = NaiveTime("15:00")!
4849
NaiveDateFormatter(timeStyle: .short).string(from: time)
4950
// prints "3:00 PM"
5051

51-
let dateTime = NaiveDateTime("2017-11-01T15:30:00")!
52+
let dateTime = NaiveDateTime("2021-11-01T15:30:00")!
5253
NaiveDateFormatter(dateStyle: .short, timeStyle: .short).string(from: dateTime)
53-
// prints "Nov 1, 2017 at 3:30 PM"
54+
// prints "Nov 1, 2021 at 3:30 PM"
5455
```
5556

5657
### Convert
5758

58-
When you do need time zones, convert `NaiveDate` to `Date`:
59+
When you do need to work with time zones, simply convert `NaiveDate` to `Date`:
5960

6061
```swift
61-
let date = NaiveDate(year: 2017, month: 10, day: 1)
62+
let date = NaiveDate(year: 2021, month: 10, day: 1)
6263

6364
// Creates `Date` in a calendar's time zone
64-
// "2017-10-01T00:00:00+0300" if user is in MSK
65+
// "2021-10-01T00:00:00+0300" if user is in MSK
6566
Calendar.current.date(from: date)
6667
```
6768

6869
```swift
6970
let dateTime = NaiveDateTime(
70-
date: NaiveDate(year: 2017, month: 10, day: 1),
71+
date: NaiveDate(year: 2021, month: 10, day: 1),
7172
time: NaiveTime(hour: 15, minute: 30, second: 0)
7273
)
7374

7475
// Creates `Date` in a calendar's time zone
75-
// "2017-10-01T15:30:00+0300" if user is in MSK
76+
// "2021-10-01T15:30:00+0300" if user is in MSK
7677
Calendar.current.date(from: dateTime)
7778
```
7879

0 commit comments

Comments
 (0)