Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
xprnio3756yBut that makes sense from a development standpoint, doesn't it? Want to get the name of the month from an array - the month can be used as the index in that array. Want to get the numerical representation of the month - +1 it. It seems like a better approach than to have to - 1 it for the first case just to get the benefit of not having to +1 it when needing the numerical representation of it.
-
@xprnio that might be true but it's more important to be consistent so it's much easier to code and later read.
It doesn't seem like a big deal but when you're reading some code you don't want to have to think about these things. -
devios157706yHow are you getting the month value? Date is based on a timestamp so it doesn’t have a month field, and my understanding was Calendar.components returns 1-based months.
-
devios157706yThe Calendar library is actually pretty handy. See component(from:) in https://developer.apple.com/documen....
-
sSam15016y@xprnio no, it doesn't make sense? Months can be identified by numbers, so why the fuck would i want my month value to be 4 when it's representing 5th month (May)? I don't care that there's a function that converts from numbers to names, it should be the function's job to minus 1 from value not your job.
-
devios157706y@xprnio No I disagree. If the day and year values are both 1-based, the month should be too. Just because you *could* look up a month name in an array doesn't mean that you necessarily have to. If I were just writing a date in numeric form, there's no array and nothing to index. It doesn't make sense that I would have to +1 the month field but not the others. Consistency is what matters here.
The Calendar library does it right though: it returns the date component as a value of the count of that many units. So the fifth month would have a month component value of 5.
I just tested it and it does return 1-based months. -
xprnio3756y@sSam @devios1 Then let's put it this way. The date is always a number, same goes for a year. But a month isn't always a number. Yes, it can be represented in one, but do you tell your friends that "Hey, meet me on the 7th of the 3rd month" or do you say "meet me on the 7th of March"? That's at least how I reason with it. Same goes for days (0-6). You don't ask someone to meet you on the 3rd day of the week you ask them to meet you on Wednesday. How doesn't this make sense?
-
@devios1 Well I had the problem with the Calendar library. Didn't try to read a month value, but if you construct a Date object out of Date components through the current calendar object, you need to index the months with 0.
-
xprnio3756y@sSam in that example I meant in a non-programming way, since the other example didn't seem to be understandable to you
-
xprnio3756y@sSam and there's a difference between creating a date from a string (which has a standard) and variables (which work the way they're implemented). Or are you telling me that if you have a date, and get the string representation of it, it will still have the month as a number from 0 to 11?
-
sSam15016y@xprnio I explained to you why it should be 1 indexed in a no coding example, you didn't even catch that and had to pin point it to you and now you say some shit like strings are standardized and variables are not? do you know what a variable and string is? string is a type, so you know you can have variable that's of type string...
Point is if:
date.getMonthName() returns February.
date.getMonth() should return 2.
because (saying this for 3rd time):
2019 February is 2019/02.
Arrays have nothing to do with this at all. NOTHING. If some function somewhere uses an array when working with dates it doesn't make any difference at all. This is a conceptual question. February is represented as 2019/02...
Should I expect some other guy to return January as 03 just because somewhere in the function he uses first 3 elements in array for his pet names?
Related Rants
So in Swift days start counting from 1 and months start from 0. Because why not 🤷♂️
rant
date
swift