Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Sources/SwiftDate/Supports/TimeStructures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public struct Year: CustomStringConvertible, Equatable {
// MARK: - Month

/// Defines months in a year
public enum Month: Int, CustomStringConvertible, Equatable {
public enum Month: Int, CaseIterable, CustomStringConvertible, Equatable {
case january = 0, february, march, april, may, june, july, august, september, october, november, december

public var description: String {
Expand Down Expand Up @@ -134,7 +134,7 @@ public enum Month: Int, CustomStringConvertible, Equatable {
return add(months: -(months % 12))
}

/// Returns the number of days in a this month for a given year
/// Returns the number of days in this month for a given year
///
/// - Parameter year: reference year.
/// - Returns: The number of days in this month.
Expand All @@ -148,5 +148,20 @@ public enum Month: Int, CustomStringConvertible, Equatable {
return 31
}
}

/// Returns the number of days in this month given if it is a leap year
///
/// - Parameter isLeapYear: whether the year is a leapYear.
/// - Returns: The number of days in this month.
public func numberOfDays(isLeapYear: Bool) -> Int {
switch self {
case .february:
return isLeapYear ? 29 : 28
case .april, .june, .september, .november:
return 30
default:
return 31
}
}

}