sexta-feira, 24 de julho de 2015

DateTimeUtil

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lapuinka.Util
{
    public class DateTimeUtil
    {
        public static string GetDayOfWeekName(DayOfWeek value)
        {
            switch (value)
            {
                case DayOfWeek.Friday:
                    return "sexta";
                case DayOfWeek.Monday:
                    return "segunda";
                case DayOfWeek.Saturday:
                    return "sábado";
                case DayOfWeek.Sunday:
                    return "domingo";
                case DayOfWeek.Thursday:
                    return "quinta";
                case DayOfWeek.Tuesday:
                    return "terça";
                case DayOfWeek.Wednesday:
                    return "quarta";
                default:
                    return value.ToString();
            }
        }

        public static string GetDaysOfWeekName(params DayOfWeek[] values)
        {
            if (values.Intersect(new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday }).Count() == 7)
            {
                return "diariamente";
            }

            if (values.Intersect(new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday }).Count() == 6)
            {
                return "segunda a sábado";
            }

            if (values.Intersect(new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday}).Count() == 5)
            {
                return "segunda a sexta-feira";
            }
            
            return string.Join(", ", values.OrderBy(d => d).Select(GetDayOfWeekName));
        }
    }
}


Postar um comentário