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
Copy file name to clipboardExpand all lines: README.md
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ Native `Date` type is great for working with time zones (e.g. `2017-09-29T15:00:
12
12
13
13
The `NaiveDate` library implements three types:
14
14
15
-
-`NaiveDate` (e.g. `2021-09-29`)
15
+
-`NaiveDate` (e.g. `2024-09-29`)
16
16
-`NaiveTime` (e.g. `15:30:00`)
17
-
-`NaiveDateTime` (e.g. `2021-09-29T15:30:00` - no time zone and no offset).
17
+
-`NaiveDateTime` (e.g. `2024-09-29T15:30:00` - no time zone and no offset).
18
18
19
19
They all implement `Equatable`, `Comparable`, `LosslessStringConvertible`, and `Codable` protocols. Naive date types can also be converted to `Date`, and `DateComponents`.
20
20
@@ -23,15 +23,15 @@ They all implement `Equatable`, `Comparable`, `LosslessStringConvertible`, and `
23
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:
24
24
25
25
```swift
26
-
NaiveDate("2021-10-01")
27
-
NaiveDate(year: 2021, month: 10, day: 1)
26
+
NaiveDate("2024-10-01")
27
+
NaiveDate(year: 2024, month: 10, day: 1)
28
28
29
29
NaiveTime("15:30:00")
30
30
NaiveTime(hour: 15, minute: 30, second: 0)
31
31
32
-
NaiveDateTime("2021-10-01T15:30")
32
+
NaiveDateTime("2024-10-01T15:30")
33
33
NaiveDateTime(
34
-
date: NaiveDate(year: 2021, month: 10, day: 1),
34
+
date: NaiveDate(year: 2024, month: 10, day: 1),
35
35
time: NaiveTime(hour: 15, minute: 30, second: 0)
36
36
)
37
37
```
@@ -41,51 +41,50 @@ NaiveDateTime(
41
41
Format dates without having to worry about time zones:
When you do need to work with time zones, simply convert `NaiveDate` to `Date`:
60
60
61
61
```swift
62
-
let date =NaiveDate(year: 2021, month: 10, day: 1)
62
+
let date =NaiveDate(year: 2024, month: 10, day: 1)
63
63
64
64
// Creates `Date` in a calendar's time zone
65
-
// "2021-10-01T00:00:00+0300" if user is in MSK
65
+
// "2024-10-01T00:00:00+0300" if user is in MSK
66
66
Calendar.current.date(from: date)
67
67
```
68
68
69
69
```swift
70
70
let dateTime =NaiveDateTime(
71
-
date: NaiveDate(year: 2021, month: 10, day: 1),
71
+
date: NaiveDate(year: 2024, month: 10, day: 1),
72
72
time: NaiveTime(hour: 15, minute: 30, second: 0)
73
73
)
74
74
75
75
// Creates `Date` in a calendar's time zone
76
-
// "2021-10-01T15:30:00+0300" if user is in MSK
76
+
// "2024-10-01T15:30:00+0300" if user is in MSK
77
77
Calendar.current.date(from: dateTime)
78
78
```
79
79
80
80
**Important!** The naive types are called this way because they don’t have a time zone associated with them. This means the date may not actually exist in some areas in the world, even though they are “valid”. For example, when daylight saving changes are applied the clock typically moves forward or backward by one hour. This means certain dates never occur or may occur more than once. If you need to do any precise manipulations with time, always use native `Date` and `Calendar`.
0 commit comments