Skip to content

Commit

Permalink
Update Date+Utilities.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
rismay-luassat committed Jun 25, 2024
1 parent 8c90e54 commit 9cd5eb8
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions Sources/WrkstrmFoundation/Extensions/Dates/Date+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import Foundation
#endif

extension Date {
/// Retrieves a specific component (e.g., year, month, day) from the date.
///
/// This method uses the `Foundation.Calendar` to extract a specified date component from the `Date` instance.
/// You can specify a custom calendar to be used for the extraction; if none is provided, the default calendar is used.
///
/// - Parameters:
/// - component: The `Calendar.Component` to extract from the date. This parameter can be any value of the `Calendar.Component` enumeration such as `.year`, `.month`, `.day`, etc.
/// - calendar: An optional `Calendar` instance to use for the extraction. Defaults to the current calendar as returned by `Calendar.default`.
/// - Returns: An `Int` representing the value of the specified component. For example, if `.year` is requested, it returns the year part of the date.
public func component(
_ component: Foundation.Calendar.Component,
calendar: Foundation.Calendar = .default) -> Int
{
calendar.component(component, from: self)
}
/// Retrieves a specific component (e.g., year, month, day) from the date.
///
/// This method uses the `Foundation.Calendar` to extract a specified date component from the
/// `Date` instance. You can specify a custom calendar to be used for the extraction; if none is
/// provided, the default calendar is used.
///
/// - Parameters:
/// - component: The `Calendar.Component` to extract from the date. This parameter can be any
/// value of the `Calendar.Component` enumeration such as `.year`, `.month`, `.day`, etc.
/// - calendar: An optional `Calendar` instance to use for the extraction. Defaults to the
/// current calendar as returned by `Calendar.default`.
/// - Returns: An `Int` representing the value of the specified component. For example, if `.year`
/// is requested, it returns the year part of the date.
public func component(
_ component: Foundation.Calendar.Component,
calendar: Foundation.Calendar = .default
) -> Int {
calendar.component(component, from: self)
}
}

0 comments on commit 9cd5eb8

Please sign in to comment.