Ejemplo n.º 1
0
        /// <summary>
        /// 시작 날짜와 마지막 날짜를 받아서 요일/날짜  리스트를 반환
        /// </summary>
        /// <param name="startDate">시작날짜</param>
        /// <param name="endDate">마지막날짜</param>
        /// <returns>요일/날짜 리스트</returns>
        public List <DateWeek> getWeekDateList(string startDate, string endDate)
        {
            List <DateWeek> dateWeekList = new List <DateWeek>();

            string[] dayOfWeek   = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
            string[] dayOfWeekKr = { "월요일", "화요일", "수요일", "목요일", "금요일", "토요일", "일요일" };

            string[] startSwap = startDate.Split('-');
            int      startYear = Convert.ToInt32(startSwap[0]), startMonth = Convert.ToInt32(startSwap[1]), startDay = Convert.ToInt32(startSwap[2]);

            string[] endSwap = endDate.Split('-');
            int      endYear = Convert.ToInt32(endSwap[0]), endMonth = Convert.ToInt32(endSwap[1]), endDay = Convert.ToInt32(endSwap[2]);

            if (startDay > endDay)
            {
                return(null);
            }

            for (int i = startDay; i <= endDay; i++)
            {
                DateWeek dateWeek = new DateWeek();
                DateTime dateTime = new DateTime(startYear, startMonth, i);
                for (int j = 0; j < dayOfWeek.Length; j++)
                {
                    if (dateTime.DayOfWeek.ToString().Substring(0, 3) == dayOfWeek[j])
                    {
                        dateWeek.week = dayOfWeekKr[j];
                        break;
                    }
                }
                dateWeek.date = startYear + "-" + startMonth.ToString().PadLeft(2, '0') + "-" + i.ToString().PadLeft(2, '0');

                dateWeekList.Add(dateWeek);
            }


            return(dateWeekList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 년, 월, 일을 받아서 해당 주의 날짜와 요일을 List로 반환
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public List <DateWeek> getWeekOfFirstDay(int year, int month, int day)
        {
            string[] dayOfWeek   = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
            string[] dayOfWeekKr = { "월요일", "화요일", "수요일", "목요일", "금요일", "토요일", "일요일" };

            List <DateWeek> dateWeekList = new List <DateWeek>();
            int             dayNum       = 0;

            DateTime dateTime = new DateTime(year, month, day);

            //전달받은 날짜의 요일을 확인
            for (int i = 0; i < dayOfWeek.Length; i++)
            {
                //요일에 따라서 해당 날짜에서 뺄값을 지정
                if (dateTime.DayOfWeek.ToString().Substring(0, 3) == dayOfWeek[i])
                {
                    dayNum = i;
                }
            }
            //주 첫날짜 구하기
            day = day - dayNum;

            //날짜가 0보다 작으면 전 월의 마지막 날짜를 구해서 계산
            if (day < 1)
            {
                month -= 1;
                day    = DateTime.DaysInMonth(year, month) + day;
            }

            //구해진 날짜와 요일을 리스트에 입력
            for (int i = 0; i < 7; i++)
            {
                DateWeek dateWeek = new DateWeek(year + "-" + month.ToString().PadLeft(2, '0') + "-" + (day + i).ToString().PadLeft(2, '0'), dayOfWeekKr[i]);
                dateWeekList.Add(dateWeek);
            }

            return(dateWeekList);
        }