Skip to content

Commit 9c4f9be

Browse files
committed
Add documentation
1 parent e761250 commit 9c4f9be

1 file changed

Lines changed: 98 additions & 6 deletions

File tree

Sources/NaiveDateFormatStyle.swift

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,55 @@ public extension NaiveDate {
1010
var timeZone: TimeZone
1111
var capitalizationContext: FormatStyleCapitalizationContext
1212

13+
/// Creates a format style for a NaiveDate.
14+
///
15+
/// - Parameters:
16+
/// - date: The style to use for formatting the date component. Defaults to `nil`.
17+
/// - time: The style to use for formatting the time component. Defaults to `nil`.
18+
/// - locale: The locale to use for formatting. Defaults to `autoupdatingCurrent`.
19+
/// - calendar: The calendar to use for formatting. Defaults to `autoupdatingCurrent`.
20+
/// - timeZone: The time zone to use for formatting. Defaults to `autoupdatingCurrent`.
21+
/// - capitalizationContext: The context for capitalization. Defaults to `unknown`.
1322
public init(date: Date.FormatStyle.DateStyle? = nil,
1423
time: Date.FormatStyle.TimeStyle? = nil,
1524
locale: Locale = .autoupdatingCurrent,
1625
calendar: Calendar = .autoupdatingCurrent,
1726
timeZone: TimeZone = .autoupdatingCurrent,
1827
capitalizationContext: FormatStyleCapitalizationContext = .unknown) {
1928
self.date = date
29+
self.time = time
2030
self.locale = locale
2131
self.calendar = calendar
2232
self.timeZone = timeZone
2333
self.capitalizationContext = capitalizationContext
2434
}
2535

36+
/// Formats the given NaiveDate value.
37+
///
38+
/// - Parameter value: The NaiveDate value to format.
39+
/// - Returns: A formatted string representing the NaiveDate.
2640
public func format(_ value: NaiveDate) -> String {
2741
calendar.date(from: value).map { date in
2842
let dateStyle = Date.FormatStyle(
2943
date: self.date,
30-
time: time,
44+
time: self.time,
3145
locale: locale,
3246
calendar: calendar,
3347
timeZone: timeZone,
3448
capitalizationContext: capitalizationContext
3549
)
36-
3750
return date.formatted(dateStyle)
3851
} ?? ""
3952
}
4053

54+
/// Returns a new format style with the specified locale.
55+
///
56+
/// - Parameter locale: The locale to apply to the format style.
57+
/// - Returns: A new `NaiveDate.FormatStyle` with the given locale.
4158
public func locale(_ locale: Locale) -> NaiveDate.FormatStyle {
4259
.init(
4360
date: date,
61+
time: time,
4462
locale: locale,
4563
calendar: calendar,
4664
timeZone: timeZone,
@@ -49,14 +67,27 @@ public extension NaiveDate {
4967
}
5068
}
5169

70+
/// Formats the NaiveDate using the provided format style.
71+
///
72+
/// - Parameter format: The format style to apply.
73+
/// - Returns: The formatted string output.
5274
func formatted<F: Foundation.FormatStyle>(_ format: F) -> F.FormatOutput where F.FormatInput == NaiveDate {
5375
format.format(self)
5476
}
5577

78+
/// Formats the NaiveDate using the default format style.
79+
///
80+
/// - Returns: A formatted string representation of the NaiveDate.
5681
func formatted() -> String {
5782
formatted(FormatStyle())
5883
}
5984

85+
/// Formats the NaiveDate with specified date and time styles.
86+
///
87+
/// - Parameters:
88+
/// - date: The style to use for formatting the date component.
89+
/// - time: The style to use for formatting the time component.
90+
/// - Returns: A formatted string representation of the NaiveDate.
6091
func formatted(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle = .omitted) -> String {
6192
formatted(FormatStyle(date: date, time: time))
6293
}
@@ -72,37 +103,55 @@ public extension NaiveTime {
72103
var timeZone: TimeZone
73104
var capitalizationContext: FormatStyleCapitalizationContext
74105

106+
/// Creates a format style for a NaiveTime.
107+
///
108+
/// - Parameters:
109+
/// - dateStyle: The style to use for formatting the date component. Defaults to `nil`.
110+
/// - timeStyle: The style to use for formatting the time component. Defaults to `nil`.
111+
/// - locale: The locale to use for formatting. Defaults to `autoupdatingCurrent`.
112+
/// - calendar: The calendar to use for formatting. Defaults to `autoupdatingCurrent`.
113+
/// - timeZone: The time zone to use for formatting. Defaults to `autoupdatingCurrent`.
114+
/// - capitalizationContext: The context for capitalization. Defaults to `unknown`.
75115
public init(date: Date.FormatStyle.DateStyle? = nil,
76116
time: Date.FormatStyle.TimeStyle? = nil,
77117
locale: Locale = .autoupdatingCurrent,
78118
calendar: Calendar = .autoupdatingCurrent,
79119
timeZone: TimeZone = .autoupdatingCurrent,
80120
capitalizationContext: FormatStyleCapitalizationContext = .unknown) {
81121
self.date = date
122+
self.time = time
82123
self.locale = locale
83124
self.calendar = calendar
84125
self.timeZone = timeZone
85126
self.capitalizationContext = capitalizationContext
86127
}
87128

129+
/// Formats the given NaiveTime value.
130+
///
131+
/// - Parameter value: The NaiveTime value to format.
132+
/// - Returns: A formatted string representing the NaiveTime.
88133
public func format(_ value: NaiveTime) -> String {
89134
calendar.date(from: value).map { date in
90135
let dateStyle = Date.FormatStyle(
91136
date: self.date,
92-
time: time,
137+
time: self.time,
93138
locale: locale,
94139
calendar: calendar,
95140
timeZone: timeZone,
96141
capitalizationContext: capitalizationContext
97142
)
98-
99143
return date.formatted(dateStyle)
100144
} ?? ""
101145
}
102146

103-
public func locale(_ locale: Locale) -> NaiveDate.FormatStyle {
147+
/// Returns a new format style with the specified locale.
148+
///
149+
/// - Parameter locale: The locale to apply to the format style.
150+
/// - Returns: A new `NaiveTime.FormatStyle` with the given locale.
151+
public func locale(_ locale: Locale) -> NaiveTime.FormatStyle {
104152
.init(
105153
date: date,
154+
time: time,
106155
locale: locale,
107156
calendar: calendar,
108157
timeZone: timeZone,
@@ -111,14 +160,27 @@ public extension NaiveTime {
111160
}
112161
}
113162

163+
/// Formats the NaiveTime using the provided format style.
164+
///
165+
/// - Parameter format: The format style to apply.
166+
/// - Returns: The formatted string output.
114167
func formatted<F: Foundation.FormatStyle>(_ format: F) -> F.FormatOutput where F.FormatInput == NaiveTime {
115168
format.format(self)
116169
}
117170

171+
/// Formats the NaiveTime using the default format style.
172+
///
173+
/// - Returns: A formatted string representation of the NaiveTime.
118174
func formatted() -> String {
119175
formatted(FormatStyle())
120176
}
121177

178+
/// Formats the NaiveTime with specified date and time styles.
179+
///
180+
/// - Parameters:
181+
/// - date: The style to use for formatting the date component.
182+
/// - time: The style to use for formatting the time component.
183+
/// - Returns: A formatted string representation of the NaiveTime.
122184
func formatted(date: Date.FormatStyle.DateStyle = .omitted, time: Date.FormatStyle.TimeStyle) -> String {
123185
formatted(FormatStyle(date: date, time: time))
124186
}
@@ -134,6 +196,15 @@ public extension NaiveDateTime {
134196
var timeZone: TimeZone
135197
var capitalizationContext: FormatStyleCapitalizationContext
136198

199+
/// Creates a format style for a NaiveDateTime.
200+
///
201+
/// - Parameters:
202+
/// - dateStyle: The style to use for formatting the date component. Defaults to `nil`.
203+
/// - timeStyle: The style to use for formatting the time component. Defaults to `nil`.
204+
/// - locale: The locale to use for formatting. Defaults to `autoupdatingCurrent`.
205+
/// - calendar: The calendar to use for formatting. Defaults to `autoupdatingCurrent`.
206+
/// - timeZone: The time zone to use for formatting. Defaults to `autoupdatingCurrent`.
207+
/// - capitalizationContext: The context for capitalization. Defaults to `unknown`.
137208
public init(date: Date.FormatStyle.DateStyle? = nil,
138209
time: Date.FormatStyle.TimeStyle? = nil,
139210
locale: Locale = .autoupdatingCurrent,
@@ -147,7 +218,11 @@ public extension NaiveDateTime {
147218
self.timeZone = timeZone
148219
self.capitalizationContext = capitalizationContext
149220
}
150-
221+
222+
/// Formats the given NaiveDateTime value.
223+
///
224+
/// - Parameter value: The NaiveDateTime value to format.
225+
/// - Returns: A formatted string representing the NaiveDateTime.
151226
public func format(_ value: NaiveDateTime) -> String {
152227
calendar.date(from: value).map { date in
153228
let dateStyle = Date.FormatStyle(
@@ -163,6 +238,10 @@ public extension NaiveDateTime {
163238
} ?? ""
164239
}
165240

241+
/// Returns a new format style with the specified locale.
242+
///
243+
/// - Parameter locale: The locale to apply to the format style.
244+
/// - Returns: A new `NaiveDateTime.FormatStyle` with the given locale.
166245
public func locale(_ locale: Locale) -> NaiveDate.FormatStyle {
167246
.init(
168247
date: date,
@@ -174,14 +253,27 @@ public extension NaiveDateTime {
174253
}
175254
}
176255

256+
/// Formats the NaiveDateTime using the provided format style.
257+
///
258+
/// - Parameter format: The format style to apply.
259+
/// - Returns: The formatted string output.
177260
func formatted<F: Foundation.FormatStyle>(_ format: F) -> F.FormatOutput where F.FormatInput == NaiveDateTime {
178261
format.format(self)
179262
}
180263

264+
/// Formats the NaiveDateTime using the default format style.
265+
///
266+
/// - Returns: A formatted string representation of the NaiveDateTime.
181267
func formatted() -> String {
182268
formatted(FormatStyle())
183269
}
184270

271+
/// Formats the NaiveDateTime with specified date and time styles.
272+
///
273+
/// - Parameters:
274+
/// - date: The style to use for formatting the date component.
275+
/// - time: The style to use for formatting the time component.
276+
/// - Returns: A formatted string representation of the NaiveDateTime.
185277
func formatted(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle) -> String {
186278
formatted(FormatStyle(date: date, time: time))
187279
}

0 commit comments

Comments
 (0)