You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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**.
9
9
10
10
11
11
## Usage
12
12
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`)
15
16
-`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).
17
18
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`.
19
20
20
21
### Create
21
22
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:
23
24
24
25
```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)
27
28
28
29
NaiveTime("15:30:00")
29
30
NaiveTime(hour: 15, minute: 30, second: 0)
30
31
31
-
NaiveDateTime("2017-10-01T15:30")
32
+
NaiveDateTime("2021-10-01T15:30")
32
33
NaiveDateTime(
33
-
date: NaiveDate(year: 2017, month: 10, day: 1),
34
+
date: NaiveDate(year: 2021, month: 10, day: 1),
34
35
time: NaiveTime(hour: 15, minute: 30, second: 0)
35
36
)
36
37
```
@@ -40,39 +41,39 @@ NaiveDateTime(
40
41
Format dates without having to worry about time zones:
0 commit comments