I am trying to check if a particular day exists in a month or not. However unable to find anything of help. To give an example I tried below code in Playground;
var components = DateComponents()
components.month = 2
components.year = 2016
components.day = 30
components.calendar = Calendar.current
components.date
This gives the answer;
"Mar 1, 2016, 12:00 AM"
So what it does is it tries to manipulate with TimeZones and moves the needle. Hence I'm unable to find a way to check if a particular day exists in a given month & year. Can anyone please guide.
Related Definitions Given Year means the applicable fiscal year for which the Adjusted Weighted Votes are calculated.
year-to-year (comparative more year-to-year, superlative most year-to-year) Being compared with those of a previous year; interannual.
Related Definitions Year n means the delivery year for RA Capacity. For example, if the RA Capacity delivery year is 2023 (Year n), then Year n-3 (2020) means the year that is three years prior to the RA Capacity delivery year 2023 (Year n). In this example Year n-2 is 2021 and Year n-1 is 2022.
DateComponents
has an isValidDate
property, which you can use
for that purpose:
var components = DateComponents()
components.month = 2
components.year = 2016
components.day = 30
components.calendar = Calendar.current
print(components.isValidDate) // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With