0

I am getting Abbreviated Day Names by culture an insert into a Class model:

        var daysNames = new CultureInfo(culture).DateTimeFormat
            .AbbreviatedDayNames
            .Select((item) => new CalendarDaysItem(item.ToUppercaseFirst()))
            .ToList();

enter image description here

But i need Sort the List with a specific Week Day, i Try this sample:

        var firstDayOfWeek = new CultureInfo(culture).DateTimeFormat.FirstDayOfWeek;

        var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
            .Cast<DayOfWeek>()
            .OrderBy(x => (x - firstDayOfWeek + 7) % 7);

        var daysOfWeekOrdered = daysOfWeek.OrderBy(x => (x - firstDayOfWeek + 7) % 7);

enter image description here

But the culture is EN-US and i need to change by parameter

Fabio Santos
  • 253
  • 1
  • 4
  • 15

2 Answers2

1

I think this might solve your issue. Please try with the below code:

var dateTimes = timeBands.OrderBy(x => ((int) x.DayOfWeek + 6) % 7) .ToList()

For more info you can refer this : .OrderBy(DayOfWeek) to treat Sunday as the end of the week

Shreeraj Bhat
  • 171
  • 2
  • 13
1
            Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-PT");
            DayOfWeek firstDayOfWeek = DayOfWeek.Monday;
            var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
               .Cast<DayOfWeek>()
               .OrderBy(x => (x - firstDayOfWeek + 7) % 7)
               .Select(x => DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(x))
               .ToList();
Fabio Santos
  • 253
  • 1
  • 4
  • 15