Skip to content

Commit

Permalink
Update DateFormatter+Utilities.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
rismay-luassat committed Jun 25, 2024
1 parent 9cd5eb8 commit 128f69b
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Foundation
#endif

extension DateFormatter {

/// A formatter for representing dates in a long style format.
/// Usage: `DateFormatter.longDate.string(from: date)`
public static let longDate = { () -> DateFormatter in
Expand Down Expand Up @@ -59,21 +58,20 @@ extension DateFormatter {
}

extension Date {

/// Converts the date to a localized string with the specified style.
/// - Parameter style: The formatting style to use. Defaults to `.medium`.
/// - Returns: A localized string representation of the date.
/// Usage: `date.localizedString() or date.localizedString(with: .long)`
public func localizedString(with style: DateFormatter.Style = .medium) -> String {
switch style {
case .long:
return DateFormatter.longDate.string(from: self)
DateFormatter.longDate.string(from: self)

case .medium:
return DateFormatter.mediumDate.string(from: self)
DateFormatter.mediumDate.string(from: self)

default:
return DateFormatter.mediumDate.string(from: self)
DateFormatter.mediumDate.string(from: self)
}
}
}

0 comments on commit 128f69b

Please sign in to comment.