4

Possible Duplicate:
Finding weekend days based on culture

Is there any locale info available in .NET to know if a given date falls on a weekday or a weekend?

i would use the function:

public Boolean IsWeekend(DateTime value, CultureInfo cultureInfo)
{
   return (value.DayOfWeek == DayOfWeek.Saturday || value.DayOfWeek == DayOfWeek.Sunday);
}

But it returns invalid results for some cultures.

Has .NET already done the work to compile what days are weekends for all cultures?

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • http://stackoverflow.com/questions/2019098/finding-weekend-days-based-on-culture – Greg May 11 '12 at 20:21
  • 2
    @Greg Please [vote to close](http://stackoverflow.com/privileges/close-questions) as a duplicate when you find a duplicate question. – Gilles 'SO- stop being evil' May 11 '12 at 20:24
  • 2
    I get hesitant, not sure if it's a "good" duplicate or not. – Greg May 11 '12 at 21:07
  • It is not a duplicate, it is a question about a weekend days over the world, not the first day of the week. It is to some extent **related** but this is a different thing. – Paweł Dyda May 12 '12 at 14:51
  • Thanks for nothing, Gilles, Cody, Gred, Magnus, Hans. The other question (similar) question has no answer. While this question *is* answered, *"No, .NET doesn't have it."*. i wasn't asking ***how*** to do it, i asked if it was already done. – Ian Boyd May 16 '12 at 19:23

1 Answers1

3

It is pretty interesting question and the answer seems to be no, there is no such function in .Net. Of course you can use DateTimeFormatInfo's FirstDayOfWeek Property, but it is not good enough.

It will just tell you that there is high chance that preceding day was the weekend day. However, it is not very helpful (what about the other one and...), as there are countries that have just one day weekend. Also, in Muslim countries, they typically have Friday as a weekend day, but... Some of them have also Thursday, some Saturday, and I am sure I heard about country that has Friday and Sunday off. In this case, it would be quite hard to talk about a weekend...

I took a look at CLDR Charts, but I can't find appropriate information. It seems you are on your own.
In theory, you may think of using ICU's Calendar class which has isWeekend() method but importing a dll just to use one class out of it sounds pretty bad.

Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79