The list of diaries on the day of the week always starts on Sunday in any country?

I have this code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSMutableArray *daysNames = [NSMutableArray arrayWithArray:dateFormatter.weekdaySymbols]; NSLog(@"daysNames = %@", daysNames); 

output:

 daysNames = ( Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ) 

My question is:

If the user is in a country other than the United States, say, France or Russia, will the array begin on Sunday (and not on Monday), or should I not rely on this?

I have set alarming days. Visually, the user selects from the table view, which always has Monday in the first row. And I keep 0 or 1 in NSMutableArray based on whether the day is set or not. If daysNames [0] always corresponds to Sundays, I can easily move all the elements one position to the right and everything will display correctly, otherwise I will have a few more headaches associated with another case when the week starts on Monday and not on Sunday.

This is the complete code I wrote for this (in the United States, it works fine):

 // Set the short days names NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSMutableArray *daysNames = [NSMutableArray arrayWithArray:dateFormatter.weekdaySymbols]; NSLog(@"daysNames = %@", daysNames); // daysNames will become @"SUN MON TUE WED THU FRI SAT"; for (NSInteger i = 0; i < daysNames.count; i++) { NSUInteger length = ((NSString *)daysNames[i]).length; if (length > 3) { length = 3; } daysNames[i] = [daysNames[i] substringToIndex:length].uppercaseString; } NSString *sundayShortName = daysNames[0]; // daysNames will become @"MON TUE WED THU FRI SAT SUN"; for (NSInteger i = 1; i < daysNames.count; i++) { daysNames[i - 1] = daysNames[i]; } daysNames[daysNames.count - 1] = sundayShortName; NSMutableArray *alarmDaysShortNames = [NSMutableArray array]; for (NSInteger i = 0; i < alarm.alarmDays.count; i++) { if ([alarm.alarmDays[i] boolValue] == YES) { [alarmDaysShortNames addObject:daysNames[i]]; } } alarmCell.alarmDaysLabel.text = [alarmDaysShortNames componentsJoinedByString:@" "]; 
+5
source share
2 answers

Yes. Sunday is always a weekday that starts first on this list. You can poll NSCalendar to find out which position on this list is considered a week (Sunday for Americans, Monday for Europeans, etc.).

+3
source

Yes, you should not rely on this. If you want to start your weekday from Monday, not Sunday. You can try the following: -

 NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; [gregorian setFirstWeekday:2]; //it is for monday 
0
source

Source: https://habr.com/ru/post/1208313/


All Articles