• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CalendarWeekRule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CalendarWeekRule的典型用法代码示例。如果您正苦于以下问题:C# CalendarWeekRule类的具体用法?C# CalendarWeekRule怎么用?C# CalendarWeekRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CalendarWeekRule类属于命名空间,在下文中一共展示了CalendarWeekRule类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DateTimeFormatInfo

 public DateTimeFormatInfo()
 {
     // Construct an invariant culture DateTimeFormatInfo
     char[] comma = new char[] { ',' };
     this.isReadOnly = true;
     this.abbreviatedDayNames = "Sun,Mon,Tue,Wed,Thu,Fri,Sat".Split(comma);
     this.abbreviatedMonthGenitiveNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,".Split(comma);
     this.abbreviatedMonthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,".Split(comma);
     this.amDesignator = "AM";
     this.calendarWeekRule = CalendarWeekRule.FirstDay;
     this.dateSeparator = "/";
     this.dayNames = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".Split(comma);
     this.firstDayOfWeek = DayOfWeek.Sunday;
     this.fullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss";
     this.longDatePattern = "dddd, dd MMMM yyyy";
     this.longTimePattern = "HH:mm:ss";
     this.monthDayPattern = "MMMM dd";
     this.monthGenitiveNames = "January,February,March,April,May,June,July,August,September,October,November,December,".Split(comma);
     this.monthNames = "January,February,March,April,May,June,July,August,September,October,November,December,".Split(comma);
     this.nativeCalendarName = "Gregorian Calendar";
     this.pmDesignator = "PM";
     this.rfc1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
     this.shortDatePattern = "MM/dd/yyyy";
     this.shortestDayNames = "Su,Mo,Tu,We,Th,Fr,Sa".Split(comma);
     this.shortTimePattern = "HH:mm";
     this.sortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
     this.timeSeparator = ":";
     this.universalSortableDateTimePattern = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'";
     this.yearMonthPattern = "yyyy MMMM";
     this.calendar = new GregorianCalendar();
 }
开发者ID:memsom,项目名称:dotNetAnywhere-wb,代码行数:31,代码来源:DateTimeFormatInfo.cs


示例2: GetStartAndEndOfWeek

 public static void GetStartAndEndOfWeek(int year, int week, out DateTime startOfWeek, out DateTime endOfWeek, CalendarWeekRule cwr, DayOfWeek firstDayOfWeek)
 {
     // find the first week. 
     //CalendarWeekRule cwr = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule;
     //DayOfWeek firstDayOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
     DateTime firstdayofyear = new DateTime(year, 1, 1);
     int offset = 0;
     if (firstdayofyear.DayOfWeek != firstDayOfWeek)
     {
         // find first first day. 
         if (cwr == CalendarWeekRule.FirstFourDayWeek)
         {
             DateTime firstFullWeekStart = firstdayofyear;
             while (firstFullWeekStart.DayOfWeek != firstDayOfWeek)
                 firstFullWeekStart = firstFullWeekStart.AddDays(1);
             if (firstFullWeekStart.Subtract(firstdayofyear).Days >= 4)
                 offset = -1;
         }
         if (cwr == CalendarWeekRule.FirstDay)
             offset = -1;
     }
     startOfWeek = firstdayofyear.AddDays(7 * (week + offset));
     while (startOfWeek != firstdayofyear && startOfWeek.DayOfWeek != firstDayOfWeek)
         startOfWeek = startOfWeek.AddDays(-1);
     endOfWeek = startOfWeek;
     do
     {
         endOfWeek = endOfWeek.AddDays(1);
     } while (endOfWeek < new DateTime(year + 1, 1, 1).AddDays(-1) && endOfWeek.AddDays(1).DayOfWeek != firstDayOfWeek);
 }
开发者ID:jansater,项目名称:TypeLess,代码行数:30,代码来源:DateHelper.cs


示例3: Setup

 public void Setup()
 {
     futureTimeUS = new DateTime(2015, 9, 1);
     us = CultureInfo.GetCultureInfo("en-us");
     firstDayOfWeekUS = us.DateTimeFormat.FirstDayOfWeek;
     calendarWeekRuleUS = us.DateTimeFormat.CalendarWeekRule;
 }
开发者ID:ngunhaSO,项目名称:MovieTheaterAngular,代码行数:7,代码来源:ExtDateTime.cs


示例4: VerificationHelper

        private void VerificationHelper(DateTimeFormatInfo info, CalendarWeekRule expected, bool setter)
        {
            if (setter)
            {
                info.CalendarWeekRule = expected;
            }

            CalendarWeekRule actual = info.CalendarWeekRule;
            Assert.Equal(expected, actual);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:10,代码来源:DateTimeFormatInfoCalendarWeekRule.cs


示例5: GetLastDateOfWeek

        /// <summary>
        /// Get the last date of the week for a certain date.
        /// 
        /// Note that for ISO 8601 dates, iso8601 must be set to true.
        /// </summary>
        public static DateTime GetLastDateOfWeek(this DateTime date, bool iso8601 = false, CalendarWeekRule weekRule = CalendarWeekRule.FirstFourDayWeek, DayOfWeek firstDayOfWeek = DayOfWeek.Monday)
        {
            if (date == DateTime.MaxValue)
                return date;

            var week = date.GetWeekNumber(iso8601, weekRule, firstDayOfWeek);
            while (week == date.GetWeekNumber(iso8601, weekRule, firstDayOfWeek))
                date = date.AddDays(1);
            return date.AddDays(-1);
        }
开发者ID:niklasmelinder,项目名称:NExtra,代码行数:15,代码来源:DateTimeExtensions.cs


示例6: SchedulerDisplayInfo

        public SchedulerDisplayInfo(CultureInfo culture)
        {
            this.culture = culture;
            firstDayOfWeek = DayOfWeek.Monday;
            calendarWeekRule = CalendarWeekRule.FirstDay;

            workingDays = new bool[7];
            for(int i=0;i<7;i++)
                workingDays[i] = ((DayOfWeek)i != DayOfWeek.Saturday) && ((DayOfWeek)i != DayOfWeek.Sunday);
            workingHoursFrom = new TimeSpan(8, 0, 0);
            workingHoursTo = new TimeSpan(17, 0, 0);
        }
开发者ID:bashocz,项目名称:Scheduler,代码行数:12,代码来源:SchedulerDisplayInfo.cs


示例7: GetWeekOfYearFullDays

        private int GetWeekOfYearFullDays(DateTime time, CalendarWeekRule rule, int firstDayOfWeek, int fullDays)
        {
            GregorianCalendar gregorianCalendar = new GregorianCalendar();
            // Make the day of year to be 0-based, so that 1/1 is day 0.
            int dayOfYear = gregorianCalendar.GetDayOfYear(time) - 1; 
            //
            // Calculate the number of days between the first day of year (1/1) and the first day of the week.
            // This value will be a positive value from 0 ~ 6.  We call this value as "offset".
            //
            // If offset is 0, it means that the 1/1 is the start of the first week.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
            //     12/31    1/1     1/2     1/3     1/4     1/5     1/6
            //              +--> First week starts here.
            //
            // If offset is 1, it means that the first day of the week is 1 day ahead of 1/1.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7
            //              +--> First week starts here.
            //
            // If offset is 2, it means that the first day of the week is 2 days ahead of 1/1.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sat      Sun     Mon     Tue     Wed     Thu     Fri     Sat
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7     1/8
            //                      +--> First week starts here.

            // Day of week is 0-based.
            // Get the day of week for 1/1.  This can be derived from the day of week of the target day.
            // Note that we can get a negative value.  It's ok since we are going to make it a positive value when calculating the offset.
            int dayForJan1 = (int)gregorianCalendar.GetDayOfWeek(time) - (dayOfYear % 7);

            // Now, calculate the offset.  Subtract the first day of week from the dayForJan1.  And make it a positive value.
            int offset = (firstDayOfWeek - dayForJan1 + 14) % 7;
            if (offset != 0 && offset >= fullDays)
            {
                // If the offset is greater than the value of fullDays, it means that
                // the first week of the year starts on the week where Jan/1 falls on.
                offset -= 7;
            }
            // Calculate the day of year for specified time by taking offset into account.
            int day = dayOfYear - offset;
            if (day >= 0)
            {
                // If the day of year value is greater than zero, get the week of year.
                return (day / 7 + 1);
            }

            // Otherwise, the specified time falls on the week of previous year.
            // Call this method again by passing the last day of previous year.
            return GetWeekOfYearFullDays(time.AddDays(-(dayOfYear + 1)), rule, firstDayOfWeek, fullDays);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:52,代码来源:TaiwanCalendarGetWeekOfYear.cs


示例8: GetDayOfYearHelper

        private static int GetDayOfYearHelper(Calendar calendar, DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
        {
            int weekOfYear = calendar.GetWeekOfYear(time, rule, firstDayOfWeek);
            int dayOfYear = calendar.GetDayOfYear(time); // 1-based
            int dayOfWeek = calendar.GetDayOfWeek(time) - firstDayOfWeek + 1; // 1-based
            if (dayOfWeek <= 0)
                dayOfWeek += DaysPerWeek; // Make it a positive value
            int dayOfWeekForJan1 = dayOfWeek - (dayOfYear - 1) % DaysPerWeek; // 1-based
            if (dayOfWeekForJan1 <= 0)
                dayOfWeekForJan1 += DaysPerWeek; // Make it a positive value
            
            // When the day of specific time falls on the previous year,
            // return the number of days from January 1 directly.
            // There could be 6 weeks within a month.
            if (time.Month == 1 && weekOfYear > 6)
            {
                return dayOfWeek - dayOfWeekForJan1 + 1;
            }

            int offset = 0;
            switch (rule)
            {
                case CalendarWeekRule.FirstDay:
                    offset = dayOfWeek - dayOfWeekForJan1;
                    break;
                case CalendarWeekRule.FirstFourDayWeek:
                    if (dayOfWeekForJan1 <= 4)
                    {
                        offset = dayOfWeek - dayOfWeekForJan1;
                    }
                    else
                    {
                        offset = dayOfWeek + DaysPerWeek - dayOfWeekForJan1;
                    }

                    break;
                case CalendarWeekRule.FirstFullWeek:
                    if (dayOfWeekForJan1 == 1)
                    {
                        offset = dayOfWeek - dayOfWeekForJan1;
                    }
                    else
                    {
                        offset = dayOfWeek + DaysPerWeek - dayOfWeekForJan1;
                    }

                    break;
            }
            return (weekOfYear - 1) * DaysPerWeek + offset + 1;;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:50,代码来源:GregorianCalendarGetWeekOfYear.cs


示例9: FirstDateOfWeek

        public static DateTime FirstDateOfWeek(int year, int weekNum, CalendarWeekRule rule)
        {
            var jan1 = new DateTime(year, 1, 1);

            var daysOffset = DayOfWeek.Monday - jan1.DayOfWeek;
            var firstMonday = jan1.AddDays(daysOffset);

            var cal = CultureInfo.CurrentCulture.Calendar;
            var firstWeek = cal.GetWeekOfYear(jan1, rule, DayOfWeek.Monday);

            if (firstWeek <= 1)
                weekNum -= 1;

            return firstMonday.AddDays(weekNum * 7);
        }
开发者ID:RHMGLtd,项目名称:sourcecode,代码行数:15,代码来源:dateExtensions.cs


示例10: GetWeekOfYear

 public void GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     Assert.InRange(rule, (CalendarWeekRule)0, (CalendarWeekRule)3);
     int expected = 0;
     if (rule == CalendarWeekRule.FirstDay)
     {
         expected = GetWeekOfYearFirstDay(time, (int)firstDayOfWeek);
     }
     else if (rule == CalendarWeekRule.FirstFullWeek)
     {
         expected = GetWeekOfYearFullDays(time, rule, (int)firstDayOfWeek, 7);
     }
     else
     {
         expected = GetWeekOfYearFullDays(time, rule, (int)firstDayOfWeek, 4);
     }
     Assert.Equal(expected, new TaiwanCalendar().GetWeekOfYear(time, rule, firstDayOfWeek));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:18,代码来源:TaiwanCalendarGetWeekOfYear.cs


示例11: GetCalendarWeekRuleAndFirstDayOfWeek

        /// <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);
        }
开发者ID:debop,项目名称:NFramework,代码行数:25,代码来源:WeekTool.cs


示例12: Main

        //Initiate stuff
        public Main()
        {
            InitializeComponent();

            button2.Enabled = false;
            this.comboBox1.Items.AddRange(loadNames());

            myCI = new CultureInfo("en-US");
            myCal = myCI.Calendar;

            // Gets the DTFI properties required by GetWeekOfYear.
            myCWR = myCI.DateTimeFormat.CalendarWeekRule;
            myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

            week = myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW);
            numericUpDown2.Value = week;

            SetTitle();
            loadWeekSales();
        }
开发者ID:dosjos,项目名称:VinLotteri,代码行数:21,代码来源:Main.cs


示例13: GetWeekOfYear

        // Returns the week of year for the specified DateTime. The returned value is an
        // integer between 1 and 53.
        //

        public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
        {
            if ((int)firstDayOfWeek < 0 || (int)firstDayOfWeek > 6)
            {
                throw new ArgumentOutOfRangeException(
                    nameof(firstDayOfWeek), SR.Format(SR.ArgumentOutOfRange_Range,
                    DayOfWeek.Sunday, DayOfWeek.Saturday));
            }
            Contract.EndContractBlock();
            switch (rule)
            {
                case CalendarWeekRule.FirstDay:
                    return (GetFirstDayWeekOfYear(time, (int)firstDayOfWeek));
                case CalendarWeekRule.FirstFullWeek:
                    return (GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 7));
                case CalendarWeekRule.FirstFourDayWeek:
                    return (GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4));
            }
            throw new ArgumentOutOfRangeException(
                nameof(rule), SR.Format(SR.ArgumentOutOfRange_Range,
                CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
        }
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:26,代码来源:Calendar.cs


示例14: IsSameWeek

        /// <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);
        }
开发者ID:debop,项目名称:NFramework,代码行数:12,代码来源:TimeTool.Compare.cs


示例15: GetWeekOfYear

        public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
        {
            if ((firstDayOfWeek < DayOfWeek.Sunday) || (firstDayOfWeek > DayOfWeek.Saturday))
            {
                throw new ArgumentOutOfRangeException("firstDayOfWeek", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), new object[] { DayOfWeek.Sunday, DayOfWeek.Saturday }));
            }
            switch (rule)
            {
                case CalendarWeekRule.FirstDay:
                    return this.GetFirstDayWeekOfYear(time, (int) firstDayOfWeek);

                case CalendarWeekRule.FirstFullWeek:
                    return this.GetWeekOfYearFullDays(time, rule, (int) firstDayOfWeek, 7);

                case CalendarWeekRule.FirstFourDayWeek:
                    return this.GetWeekOfYearFullDays(time, rule, (int) firstDayOfWeek, 4);
            }
            throw new ArgumentOutOfRangeException("rule", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), new object[] { CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek }));
        }
开发者ID:randomize,项目名称:VimConfig,代码行数:19,代码来源:Calendar.cs


示例16: GetWeekOfYearFullDays

 internal int GetWeekOfYearFullDays(DateTime time, CalendarWeekRule rule, int firstDayOfWeek, int fullDays)
 {
     int num4 = this.GetDayOfYear(time) - 1;
     int num = ((int) this.GetDayOfWeek(time)) - (num4 % 7);
     int num2 = ((firstDayOfWeek - num) + 14) % 7;
     if ((num2 != 0) && (num2 >= fullDays))
     {
         num2 -= 7;
     }
     int num3 = num4 - num2;
     if (num3 >= 0)
     {
         return ((num3 / 7) + 1);
     }
     return this.GetWeekOfYearFullDays(time.AddDays((double) -(num4 + 1)), rule, firstDayOfWeek, fullDays);
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:16,代码来源:Calendar.cs


示例17: GetWeekOfYear

	/// <summary>
	/// A virtual method that gives the number of the week in the year.
	/// </summary>
	/// <param name="time">A 
	/// <see cref="T:System.DateTime"/> representing the date.
	/// </param>
	/// <param name="rule">The
	/// <see cref="T:System.Globalization.CalendarWeekRule"/>
	/// to be used for the calculation.
	/// </param>
	/// <param name="firstDayOfWeek">
	/// The <see cref="T:System.Globalization.DayOfWeek"/>
	/// specifying the first day in a week.
	/// </param>
	/// <returns>An integer representing the number of the week in the
	/// year, starting with 1.
	/// </returns>
	public virtual int GetWeekOfYear(DateTime time,
		CalendarWeekRule rule, 
		DayOfWeek firstDayOfWeek)
	{
		if (firstDayOfWeek < DayOfWeek.Sunday ||
		    DayOfWeek.Saturday < firstDayOfWeek)
		{
		    	throw new ArgumentOutOfRangeException("firstDayOfWeek",
				"Value is not a valid day of week.");
		}
		int year = GetYear(time);

		int days;

		while (true) {
			DateTime secondWeek = M_GetFirstDayOfSecondWeekOfYear(
				year, rule, firstDayOfWeek);
			days = M_DiffDays(time, secondWeek) + M_DaysInWeek;
			if (days >= 0)
				break;
			year -= 1;
		}

		return 1 + days/M_DaysInWeek;
	}
开发者ID:jack-pappas,项目名称:mono,代码行数:42,代码来源:Calendar.cs


示例18: GetWeekOfYear

 public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     CheckTicksRange(time.Ticks);
     // Use GregorianCalendar to get around the problem that the implmentation in Calendar.GetWeekOfYear()
     // can call GetYear() that exceeds the supported range of the Gregorian-based calendars.
     return (GregorianCalendar.GetDefaultInstance().GetWeekOfYear(time, rule, firstDayOfWeek));
 }
开发者ID:noahfalk,项目名称:corert,代码行数:7,代码来源:GregorianCalendarHelper.cs


示例19: GetParamsInfo

 //Get text represntation of the input parmeters
 private string GetParamsInfo(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     string str;
     str = string.Format("\nThe specified time: {0}).", time);
     str += string.Format("\nThe calendar week rule: {0}", rule);
     str += string.Format("\nThe first day of week: {0}", firstDayOfWeek);
     return str;
 }
开发者ID:kkurni,项目名称:corefx,代码行数:9,代码来源:GregorianCalendarGetWeekOfYears.cs


示例20: GetDayOfYear

        private int GetDayOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek, int weekOfYear, Calendar myCalendar)
        {
            int retVal = -367;
            int offset = 0;
            int dayOfWeekForJan1, dayOfYear, dayOfWeek;
            dayOfYear = myCalendar.GetDayOfYear(time); //1-based
            dayOfWeek = (int)myCalendar.GetDayOfWeek(time) - (int)firstDayOfWeek + 1; //1-based
            if (dayOfWeek <= 0)
                dayOfWeek += c_DAYS_PER_WEEK; //Make it a positive value
            dayOfWeekForJan1 = dayOfWeek - (dayOfYear - 1) % c_DAYS_PER_WEEK; //1-based
            if (dayOfWeekForJan1 <= 0)
                dayOfWeekForJan1 += c_DAYS_PER_WEEK; //Make it a positive value
                                                     // When the day of specific time falls on the previous year,
                                                     // return the number of days from January 1 directly.
                                                     // There could be 6 weeks within a month.
            if (time.Month == 1 && weekOfYear > 6)
            {
                return dayOfWeek - dayOfWeekForJan1 + 1;
            }

            switch (rule)
            {
                case CalendarWeekRule.FirstDay:
                    offset = dayOfWeek - dayOfWeekForJan1;
                    break;
                case CalendarWeekRule.FirstFourDayWeek:
                    if (dayOfWeekForJan1 <= 4)
                    {
                        offset = dayOfWeek - dayOfWeekForJan1;
                    }
                    else
                    {
                        offset = dayOfWeek + c_DAYS_PER_WEEK - dayOfWeekForJan1;
                    }

                    break;
                case CalendarWeekRule.FirstFullWeek:
                    if (dayOfWeekForJan1 == 1)
                    {
                        offset = dayOfWeek - dayOfWeekForJan1;
                    }
                    else
                    {
                        offset = dayOfWeek + c_DAYS_PER_WEEK - dayOfWeekForJan1;
                    }

                    break;
            }
            retVal = (weekOfYear - 1) * c_DAYS_PER_WEEK + offset + 1;
            return retVal;
        }
开发者ID:kkurni,项目名称:corefx,代码行数:51,代码来源:GregorianCalendarGetWeekOfYears.cs



注:本文中的CalendarWeekRule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Call类代码示例发布时间:2022-05-24
下一篇:
C# CalendarService类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap