-
I ask the following because as simple as date math may seem, I've learned enough that it is not. I just found out about
In some sense, it's kind of like With the backing of proper/existing "date" implementations, such a type should weed out February 31 as invalid (or is it? 😉) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
The catch is that such types are usually needed for writing calendaring applications. If that's what you're writing, the types present in the BCL are going to be insufficient in general, and you are advised to use NodaTime. |
Beta Was this translation helpful? Give feedback.
-
If the information consists of too few parts, there's little benifit than using integers. |
Beta Was this translation helpful? Give feedback.
-
@myokeeh I don't think having partial date type make sense. In your scenarios, you can create DateOnly object with the default values of the missing date part. For example, if you have year and month without a day, you create DateOnly(year, month, 1). you can apply this for any case that is missing the date part. Doing that will allow you to perform the needed calculations. If you can send more details about the exact scenario, you are using this partial dates and what calculations you are doing on that partial date, that can help understand what you need. doing Date calculation on dates missing parts will not make sense. To give some example why partial date doesn't make sense, imagine you are missing the year and have the month and the day. you have the month as February and the day is 29. do you consider this a correct or wrong date? |
Beta Was this translation helpful? Give feedback.
@myokeeh I don't think having partial date type make sense. In your scenarios, you can create DateOnly object with the default values of the missing date part. For example, if you have year and month without a day, you create DateOnly(year, month, 1). you can apply this for any case that is missing the date part. Doing that will allow you to perform the needed calculations.
If you can send more details about the exact scenario, you are using this partial dates and what calculations you are doing on that partial date, that can help understand what you need. doing Date calculation on dates missing parts will not make sense.
To give some example why partial date doesn't make sense, imagine y…