-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time and Date formatters are made more flexible with a structs implem…
…enting OptionSet protocol. Added the ability to specify a separator for dates. Added day of the week formatter. Naming changes.
- Loading branch information
Filipp Kosenko
committed
Sep 7, 2023
1 parent
1189371
commit 3e6a19f
Showing
4 changed files
with
155 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 28 additions & 8 deletions
36
DateFormatterConstructor/DateFormatterConstructor.docc/DateFormatterConstructor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
# ``DateFormatterConstructor`` | ||
|
||
<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@--> | ||
This is simple DateFormatter extension which allows you to create a DateFormatter instance with a specific date pattern in one line. | ||
|
||
## Overview | ||
|
||
<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@--> | ||
|
||
## Topics | ||
|
||
### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@--> | ||
|
||
- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@--> | ||
So instead of writing: | ||
```swift | ||
let formatter = DateFormatter() | ||
formatter.locale = .current | ||
formatter.timeZone = .current | ||
formatter.dateFormat = "HH:mm:ss" | ||
``` | ||
you write: | ||
```swift | ||
let formatter = DateFormatter.custom(format: .fullTime(format: .twentyFour)) | ||
``` | ||
You can also optionally select the locale and timezone: | ||
```swift | ||
let formatter = DateFormatter.custom(format: DateFormatter.DateFormat, locale: Locale(identifier: "en-US"), timeZone: .gmt) | ||
``` | ||
or leave them as default as | ||
```swift | ||
.current | ||
``` | ||
if you do not specify a format, the | ||
```swift | ||
.fullTimeAndDate | ||
``` | ||
format will be used by default: | ||
```swift | ||
let formatter = DateFormatter.custom() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters