Ejemplo n.º 1
0
 /// <summary>
 /// 해당 년도의 주차산정방식에 따라 마지막 주차를 산정합니다.
 /// </summary>
 /// <param name="year">해당 년도</param>
 /// <param name="yearStartMonth">년의 시작 월</param>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">한해의 첫번째 주차를 산정하는 방식</param>
 /// <returns>해당 년도의 마지막 주차</returns>
 public static YearAndWeek GetEndYearAndWeek(this int year,
                                             CultureInfo culture = null,
                                             WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                             int yearStartMonth = TimeSpec.CalendarYearStartMonth)
 {
     return(GetEndYearAndWeek(year, TimeCalendar.New(culture, yearStartMonth, weekOfYearRule)));
 }
Ejemplo n.º 2
0
        public static void GetWeekOfYear(this DateTime moment, CultureInfo culture, CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek,
                                         WeekOfYearRuleKind weekOfYearRule, out int year, out int weekOfYear)
        {
            var yearAndWeek = WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule);

            year       = yearAndWeek.Year ?? 0;
            weekOfYear = yearAndWeek.Week ?? 0;

            //culture.ShouldNotBeNull("culture");


            //// NOTE: ISO 8601이 FirstFourDayWeek, Monday를 기준으로 하는데 왜 이렇게 하는지 모르겠네?
            ////
            //if(weekOfYearRule == WeekOfYearRuleKind.Iso8601 && weekRule == CalendarWeekRule.FirstFourDayWeek && firstDayOfWeek == DayOfWeek.Monday)
            //{
            //    //
            //    // NOTE: see http://blogs.msdn.com/b/shawnste/archive/2006/01/24/517178.aspx
            //    //
            //    var day = culture.Calendar.GetDayOfWeek(moment);
            //    if(day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
            //    {
            //        moment = moment.AddDays(3);
            //    }
            //}

            //weekOfYear = culture.Calendar.GetWeekOfYear(moment, weekRule, firstDayOfWeek);
            //year = moment.Year;
            //if(weekOfYear >= 52 && moment.Month < 12)
            //{
            //    year--;
            //}
        }
Ejemplo n.º 3
0
        public static DateTime GetStartOfYearWeek(int year, int weekOfYear, CultureInfo culture, CalendarWeekRule weekRule,
                                                  DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRuleKind)
        {
            culture.ShouldNotBeNull("culture");
            weekOfYear.ShouldBePositive("weekOfYear");

            DateTime dateTime = new DateTime(year, 1, 1).AddDays(weekOfYear * TimeSpec.DaysPerWeek);
            int      currentYear;
            int      currentWeek;

            GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);


            // end date of week
            while (currentWeek != weekOfYear)
            {
                dateTime = dateTime.AddDays(-1);
                GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }

            // end of previous week
            while (currentWeek == weekOfYear)
            {
                dateTime = dateTime.AddDays(-1);
                GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }

            return(dateTime.AddDays(1));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// TimeCalendar를 생성합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="yearBaseMonth">한 해의 시작 월</param>
 /// <param name="weekOfYearRule">주차 계산 규칙</param>
 /// <returns>TimeCalendar 인스턴스</returns>
 public static TimeCalendar New(CultureInfo culture, int?yearBaseMonth,
                                WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar)
 {
     return(new TimeCalendar(new TimeCalendarConfig(culture, weekOfYearRule)
     {
         YearBaseMonth = yearBaseMonth
     }));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// <paramref name="yearAndWeek"/> 주차에 해당하는 기간을 <see cref="WeekRange"/> 로 반환합니다. (예: 2011년 28주차의 실제 기간)
        /// </summary>
        /// <param name="yearAndWeek">년도와 주차 정보</param>
        /// <param name="yearStartMonth">한 해의 시작 월</param>
        /// <param name="culture">문하권</param>
        /// <param name="weekOfYearRule">한해의 첫주를 산정하는 규칙</param>
        /// <returns>주차에 해당하는 한주의 기간</returns>
        public static WeekRange GetWeekRange(this YearAndWeek yearAndWeek,
                                             CultureInfo culture = null,
                                             WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                             int yearStartMonth = TimeSpec.CalendarYearStartMonth)
        {
            var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule, TimeSpan.Zero, TimeSpan.Zero);

            return(GetWeekRange(yearAndWeek, timeCalendar));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 해당 년도의 마지막 주차에 해당하는 기간을 <see cref="WeekRange"/>로 반환합니다.
        /// </summary>
        /// <param name="year">년도</param>
        /// <param name="yearStartMonth">한 해의 시작 월</param>
        /// <param name="culture">문하권</param>
        /// <param name="weekOfYearRule">한 해의 첫주를 산정하는 룰</param>
        /// <returns>마지막 주차에 해당하는 한주의 기간</returns>
        public static WeekRange GetEndWeekRangeOfYear(this int year,
                                                      CultureInfo culture = null,
                                                      WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                                      int yearStartMonth = TimeSpec.CalendarYearStartMonth)
        {
            var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule);

            return(GetEndWeekRangeOfYear(year, timeCalendar));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// TimeCalendar를 생성합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="yearBaseMonth">한 해의 시작 월</param>
 /// <param name="weekOfYearRule">주차 계산 규칙</param>
 /// <param name="startOffset">시작 오프셋</param>
 /// <param name="endOffset">완료 오프셋</param>
 /// <returns>TimeCalendar 인스턴스</returns>
 public static TimeCalendar New(CultureInfo culture, int?yearBaseMonth, WeekOfYearRuleKind weekOfYearRule, TimeSpan?startOffset,
                                TimeSpan?endOffset)
 {
     return(new TimeCalendar(new TimeCalendarConfig(culture, weekOfYearRule)
     {
         YearBaseMonth = yearBaseMonth,
         StartOffset = startOffset,
         EndOffset = endOffset
     }));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// <paramref name="yearAndWeek"/>에 <paramref name="weeks"/>만큼의 주차를 더한 주차를 계산합니다.
        /// </summary>
        /// <param name="yearAndWeek">기준 주차</param>
        /// <param name="weeks">더할 주차 값</param>
        /// <param name="yearStartMonth">한해의 시작 월</param>
        /// <param name="culture">문화권</param>
        /// <param name="weekOfYearRule">주차 산정을 위한 룰</param>
        /// <returns>기준 주차에 주차를 더한 주차 정보</returns>
        public static YearAndWeek AddWeekOfYears(this YearAndWeek yearAndWeek,
                                                 int weeks,
                                                 CultureInfo culture = null,
                                                 WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                                 int yearStartMonth = TimeSpec.CalendarYearStartMonth)
        {
            var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule);

            return(AddWeekOfYears(yearAndWeek, weeks, timeCalendar));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
        /// </summary>
        public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, CalendarWeekRule weekRule,
                                      DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRuleKind)
        {
            culture = culture.GetOrCurrentCulture();

            var leftYearWeek  = GetWeekOfYear(left, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);
            var rightYearWeek = GetWeekOfYear(right, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);

            return(Equals(leftYearWeek, rightYearWeek));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// <paramref name="weekOfYearRule"/> 에 따라 <paramref name="weekRule"/>과  <paramref name="firstDayOfWeek"/> 를 결정합니다.
        /// </summary>
        /// <param name="culture">문화권</param>
        /// <param name="weekOfYearRule">주차 계산을 위한 룰</param>
        /// <param name="weekRule">한해의 첫주를 산정하는 규칙</param>
        /// <param name="firstDayOfWeek">한주의 첫번째 요일</param>
        public static void GetCalendarWeekRuleAndFirstDayOfWeek(CultureInfo culture,
                                                                WeekOfYearRuleKind? weekOfYearRule,
                                                                out CalendarWeekRule weekRule,
                                                                out DayOfWeek firstDayOfWeek) {
            if(weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Calendar) {
                weekRule = culture.GetOrCurrentCulture().DateTimeFormat.CalendarWeekRule;
                firstDayOfWeek = culture.GetOrCurrentCulture().DateTimeFormat.FirstDayOfWeek;
            }
            else {
                weekRule = CalendarWeekRule.FirstFourDayWeek;
                firstDayOfWeek = DayOfWeek.Monday;
            }

            if(IsDebugEnabled)
                log.Debug("WeekOfyearRuleKind에 따른 CalendarWeekRule, FirstDayOfWeek 정보를 결정했습니다!!! " +
                          @"culture=[{0}], weekOfYearRule=[{1}], weekRule=[{2}], firstDayOfWeek=[{3}]",
                          culture, weekOfYearRule, weekRule, firstDayOfWeek);
        }
Ejemplo n.º 11
0
        public static int GetWeeksOfYear(int year, CultureInfo culture, CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek,
                                         WeekOfYearRuleKind weekOfYearRuleKind)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            int      currentYear;
            int      currentWeek;
            DateTime currentDay = new DateTime(year, 12, 31);

            GetWeekOfYear(currentDay, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            while (currentYear != year)
            {
                currentDay = currentDay.AddDays(-1);
                GetWeekOfYear(currentDay, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }
            return(currentWeek);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// <paramref name="yearAndWeek"/> 주차에 해당하는 기간을 <see cref="WeekRange"/> 로 반환합니다. (예: 2011년 28주차의 실제 기간)
 /// </summary>
 /// <param name="yearAndWeek">년도와 주차 정보</param>
 /// <param name="yearStartMonth">한 해의 시작 월</param>
 /// <param name="culture">문하권</param>
 /// <param name="weekOfYearRule">한해의 첫주를 산정하는 규칙</param>
 /// <returns>주차에 해당하는 한주의 기간</returns>
 public static WeekRange GetWeekRange(this YearAndWeek yearAndWeek,
                                      CultureInfo culture = null,
                                      WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                      int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule, TimeSpan.Zero, TimeSpan.Zero);
     return GetWeekRange(yearAndWeek, timeCalendar);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 해당 년도의 주차산정방식에 따라 마지막 주차를 산정합니다. 
 /// </summary>
 /// <param name="year">해당 년도</param>
 /// <param name="yearStartMonth">년의 시작 월</param>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">한해의 첫번째 주차를 산정하는 방식</param>
 /// <returns>해당 년도의 마지막 주차</returns>
 public static YearAndWeek GetEndYearAndWeek(this int year,
                                             CultureInfo culture = null,
                                             WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                             int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     return GetEndYearAndWeek(year, TimeCalendar.New(culture, yearStartMonth, weekOfYearRule));
 }
Ejemplo n.º 14
0
 public static YearAndWeek GetWeekOfYear(this DateTime moment, CultureInfo culture, WeekOfYearRuleKind weekOfYearRule)
 {
     return(WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="culture"></param>
 /// <param name="weekOfYearRuleKind"></param>
 /// <returns></returns>
 public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind)
 {
     culture = culture.GetOrCurrentCulture();
     return(IsSameWeek(left, right, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                       weekOfYearRuleKind));
 }
Ejemplo n.º 16
0
 public static YearAndWeek GetWeekOfYear(this DateTime moment, CultureInfo culture, CalendarWeekRule weekRule,
                                         DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRule)
 {
     return(WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule));
 }
Ejemplo n.º 17
0
 public static void GetWeekOfYear(this DateTime moment, CultureInfo culture, WeekOfYearRuleKind weekOfYearRule, out int year,
                                  out int weekOfYear)
 {
     GetWeekOfYear(moment, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                   weekOfYearRule, out year, out weekOfYear);
 }
Ejemplo n.º 18
0
 public static YearAndWeek GetWeekOfYear(this DateTime moment, CultureInfo culture, CalendarWeekRule weekRule,
                                         DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRule) {
     return WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule);
 }
Ejemplo n.º 19
0
 public static DateTime GetStartOfYearWeek(int year, int weekOfYear, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind)
 {
     return(GetStartOfYearWeek(year, weekOfYear, culture,
                               culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek, weekOfYearRuleKind));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 주차 계산 룰과 문화권에 따른 한주의 첫번째 요일을 구합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 계산 룰</param>
 /// <returns></returns>
 public static DayOfWeek GetFirstDayOfWeek(CultureInfo culture = null,
                                           WeekOfYearRuleKind? weekOfYearRule = null) {
     return weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Iso8601
                ? DayOfWeek.Monday
                : culture.GetOrCurrentCulture().DateTimeFormat.FirstDayOfWeek;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="culture"></param>
 /// <param name="weekOfYearRuleKind"></param>
 /// <returns></returns>
 public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind) {
     culture = culture.GetOrCurrentCulture();
     return IsSameWeek(left, right, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                       weekOfYearRuleKind);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// <paramref name="yearAndWeek"/>에 <paramref name="weeks"/>만큼의 주차를 더한 주차를 계산합니다.
 /// </summary>
 /// <param name="yearAndWeek">기준 주차</param>
 /// <param name="weeks">더할 주차 값</param>
 /// <param name="yearStartMonth">한해의 시작 월</param>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 산정을 위한 룰</param>
 /// <returns>기준 주차에 주차를 더한 주차 정보</returns>
 public static YearAndWeek AddWeekOfYears(this YearAndWeek yearAndWeek,
                                          int weeks,
                                          CultureInfo culture = null,
                                          WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                          int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule);
     return AddWeekOfYears(yearAndWeek, weeks, timeCalendar);
 }
Ejemplo n.º 23
0
        public static void GetWeekOfYear(this DateTime moment, CultureInfo culture, CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek,
                                         WeekOfYearRuleKind weekOfYearRule, out int year, out int weekOfYear) {
            var yearAndWeek = WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule);

            year = yearAndWeek.Year ?? 0;
            weekOfYear = yearAndWeek.Week ?? 0;

            //culture.ShouldNotBeNull("culture");


            //// NOTE: ISO 8601이 FirstFourDayWeek, Monday를 기준으로 하는데 왜 이렇게 하는지 모르겠네?
            ////
            //if(weekOfYearRule == WeekOfYearRuleKind.Iso8601 && weekRule == CalendarWeekRule.FirstFourDayWeek && firstDayOfWeek == DayOfWeek.Monday)
            //{
            //    //
            //    // NOTE: see http://blogs.msdn.com/b/shawnste/archive/2006/01/24/517178.aspx
            //    //
            //    var day = culture.Calendar.GetDayOfWeek(moment);
            //    if(day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
            //    {
            //        moment = moment.AddDays(3);
            //    }
            //}

            //weekOfYear = culture.Calendar.GetWeekOfYear(moment, weekRule, firstDayOfWeek);
            //year = moment.Year;
            //if(weekOfYear >= 52 && moment.Month < 12)
            //{
            //    year--;
            //}
        }
Ejemplo n.º 24
0
 public static void GetWeekOfYear(this DateTime moment, CultureInfo culture, WeekOfYearRuleKind weekOfYearRule, out int year,
                                  out int weekOfYear) {
     GetWeekOfYear(moment, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                   weekOfYearRule, out year, out weekOfYear);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 해당 년도의 마지막 주차에 해당하는 기간을 <see cref="WeekRange"/>로 반환합니다.
 /// </summary>
 /// <param name="year">년도</param>
 /// <param name="yearStartMonth">한 해의 시작 월</param>
 /// <param name="culture">문하권</param>
 /// <param name="weekOfYearRule">한 해의 첫주를 산정하는 룰</param>
 /// <returns>마지막 주차에 해당하는 한주의 기간</returns>
 public static WeekRange GetEndWeekRangeOfYear(this int year,
                                               CultureInfo culture = null,
                                               WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar,
                                               int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     var timeCalendar = TimeCalendar.New(culture, yearStartMonth, weekOfYearRule);
     return GetEndWeekRangeOfYear(year, timeCalendar);
 }
Ejemplo n.º 26
0
 public static int GetWeeksOfYear(int year, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind)
 {
     return(GetWeeksOfYear(year, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                           weekOfYearRuleKind));
 }
Ejemplo n.º 27
0
 public static int GetWeeksOfYear(int year, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind) {
     return GetWeeksOfYear(year, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                           weekOfYearRuleKind);
 }
Ejemplo n.º 28
0
 public static YearAndWeek GetWeekOfYear(this DateTime moment, CultureInfo culture, WeekOfYearRuleKind weekOfYearRule) {
     return WeekTool.GetYearAndWeek(moment, culture, weekOfYearRule);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// 주차 계산 룰과 문화권에 따른 주차 계산 룰을 구합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 계산 룰</param>
 /// <returns></returns>
 public static CalendarWeekRule GetCalendarWeekRule(CultureInfo culture = null,
                                                    WeekOfYearRuleKind? weekOfYearRule = null) {
     return weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Iso8601
                ? CalendarWeekRule.FirstFourDayWeek
                : culture.GetOrCurrentCulture().DateTimeFormat.CalendarWeekRule;
 }
Ejemplo n.º 30
0
        public static int GetWeeksOfYear(int year, CultureInfo culture, CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek,
                                         WeekOfYearRuleKind weekOfYearRuleKind) {
            if(culture == null) {
                throw new ArgumentNullException("culture");
            }

            int currentYear;
            int currentWeek;
            DateTime currentDay = new DateTime(year, 12, 31);
            GetWeekOfYear(currentDay, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            while(currentYear != year) {
                currentDay = currentDay.AddDays(-1);
                GetWeekOfYear(currentDay, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }
            return currentWeek;
        }
Ejemplo n.º 31
0
 /// <summary>
 /// 생성자
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 산정 룰</param>
 public TimeCalendarConfig(CultureInfo culture, WeekOfYearRuleKind weekOfYearRule = WeekOfYearRuleKind.Calendar)
     : this()
 {
     Culture        = culture.GetOrCurrentCulture();
     WeekOfYearRule = weekOfYearRule;
 }
Ejemplo n.º 32
0
 public static DateTime GetStartOfYearWeek(int year, int weekOfYear, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind) {
     return GetStartOfYearWeek(year, weekOfYear, culture,
                               culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek, weekOfYearRuleKind);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
        /// </summary>
        public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, CalendarWeekRule weekRule,
                                      DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRuleKind) {
            culture = culture.GetOrCurrentCulture();

            var leftYearWeek = GetWeekOfYear(left, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);
            var rightYearWeek = GetWeekOfYear(right, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);

            return Equals(leftYearWeek, rightYearWeek);
        }
Ejemplo n.º 34
0
        public static DateTime GetStartOfYearWeek(int year, int weekOfYear, CultureInfo culture, CalendarWeekRule weekRule,
                                                  DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRuleKind) {
            culture.ShouldNotBeNull("culture");
            weekOfYear.ShouldBePositive("weekOfYear");

            DateTime dateTime = new DateTime(year, 1, 1).AddDays(weekOfYear * TimeSpec.DaysPerWeek);
            int currentYear;
            int currentWeek;

            GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);


            // end date of week
            while(currentWeek != weekOfYear) {
                dateTime = dateTime.AddDays(-1);
                GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }

            // end of previous week
            while(currentWeek == weekOfYear) {
                dateTime = dateTime.AddDays(-1);
                GetWeekOfYear(dateTime, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind, out currentYear, out currentWeek);
            }

            return dateTime.AddDays(1);
        }