当前位置: 首页>>代码示例>>C#>>正文


C# CalendarWeekRule类代码示例

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


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


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