/// <summary>
        /// Weeks the of year.
        /// </summary>
        /// <param name="datetime">The datetime.</param>
        /// <param name="firstDayOfWeek">The first day of week.</param>
        /// <returns></returns>
        public static int WeekOfYear(this DateTime datetime, DayOfWeek firstDayOfWeek)
        {
            DateTimeFormatInfo dateinf  = new DateTimeFormatInfo();
            CalendarWeekRule   weekrule = dateinf.CalendarWeekRule;

            return(WeekOfYear(datetime, weekrule, firstDayOfWeek));
        }
 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();
 }
 public void Setup()
 {
     futureTimeUS = new DateTime(2015, 9, 1);
     us = CultureInfo.GetCultureInfo("en-us");
     firstDayOfWeekUS = us.DateTimeFormat.FirstDayOfWeek;
     calendarWeekRuleUS = us.DateTimeFormat.CalendarWeekRule;
 }
示例#4
0
 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();
 }
示例#5
0
        /// <summary>
        /// Weeks the of year.
        /// </summary>
        /// <param name="datetime">The datetime.</param>
        /// <param name="weekRule">The weekRule.</param>
        /// <returns></returns>
        public static int WeekOfYear(this DateTime datetime, CalendarWeekRule weekRule)
        {
            DateTimeFormatInfo dateInfo       = new DateTimeFormatInfo();
            DayOfWeek          firstDayOfWeek = dateInfo.FirstDayOfWeek;

            return(WeekOfYear(datetime, weekRule, firstDayOfWeek));
        }
示例#6
0
 internal DateTimeFormatInfo(StreamReader s, string calendarName)
 {
     char[] comma = new char[] { ',' };
     this.abbreviatedDayNames           = s.ReadLine().Split(comma);
     this.abbreviatedMonthGenitiveNames = s.ReadLine().Split(comma);
     this.abbreviatedMonthNames         = s.ReadLine().Split(comma);
     this.amDesignator        = s.ReadLine();
     this.calendarWeekRule    = (CalendarWeekRule)int.Parse(s.ReadLine());
     this.dateSeparator       = s.ReadLine();
     this.dayNames            = s.ReadLine().Split(comma);
     this.firstDayOfWeek      = (DayOfWeek)int.Parse(s.ReadLine());
     this.fullDateTimePattern = s.ReadLine();
     this.longDatePattern     = s.ReadLine();
     this.longTimePattern     = s.ReadLine();
     this.monthDayPattern     = s.ReadLine();
     this.monthGenitiveNames  = s.ReadLine().Split(comma);
     this.monthNames          = s.ReadLine().Split(comma);
     this.nativeCalendarName  = s.ReadLine();
     s.ReadLine();                                         // TODO: Appears to be a mistake in the culture files. Extra line added.
     this.pmDesignator                     = s.ReadLine();
     this.rfc1123Pattern                   = s.ReadLine(); // This is always the same, so does it need to be in the culture file?
     this.shortDatePattern                 = s.ReadLine();
     this.shortestDayNames                 = s.ReadLine().Split(comma);
     this.shortTimePattern                 = s.ReadLine();
     this.sortableDateTimePattern          = s.ReadLine();    // This is always the same
     this.timeSeparator                    = s.ReadLine();
     this.universalSortableDateTimePattern = s.ReadLine();    // This is always the same
     this.yearMonthPattern                 = s.ReadLine();
     this.calendar = Calendar.CreateByName(calendarName);
 }
        }         // GetWeekOfYear

        // ----------------------------------------------------------------------
        public static void GetWeekOfYear(DateTime moment, CultureInfo culture,
                                         CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek, YearWeekType yearWeekType, out int year, out int weekOfYear)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            if (yearWeekType == YearWeekType.Iso8601 && weekRule == CalendarWeekRule.FirstFourDayWeek && firstDayOfWeek == DayOfWeek.Monday)
            {
                // see http://blogs.msdn.com/b/shawnste/archive/2006/01/24/517178.aspx
                DayOfWeek 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--;
            }
        }         // GetWeekOfYear
        }         // GetStartOfYearWeek

        // ----------------------------------------------------------------------
        public static DateTime GetStartOfYearWeek(int year, int weekOfYear, CultureInfo culture,
                                                  CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek, YearWeekType yearWeekType)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (weekOfYear < 1)
            {
                throw new ArgumentOutOfRangeException("weekOfYear");
            }

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

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


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

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

            return(dateTime.AddDays(1));
        }         // GetStartOfYearWeek
示例#9
0
 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));
 }
示例#10
0
文件: Calendar.cs 项目: zsd4yr/corefx
        public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
        {
            if (firstDayOfWeek < DayOfWeek.Sunday || firstDayOfWeek > DayOfWeek.Saturday)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(firstDayOfWeek),
                          firstDayOfWeek,
                          SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
            }
            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));

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(rule),
                          rule,
                          SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
            }
        }
示例#11
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--;
            //}
        }
示例#12
0
 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);
 }
        public void CalendarWeekRule_Set(CalendarWeekRule newCalendarWeekRule)
        {
            var format = new DateTimeFormatInfo();

            format.CalendarWeekRule = newCalendarWeekRule;
            Assert.Equal(newCalendarWeekRule, format.CalendarWeekRule);
        }
        /// <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);
        }
        public PagedList <WeekSummary> GetWeeklyReports(IEnumerable <Jogging> joggings, ReportParameters reportParameters)
        {
            List <WeekSummary> weekSummaries = new List <WeekSummary>();
            CultureInfo        myCI          = new CultureInfo("en-US");
            Calendar           myCal         = myCI.Calendar;
            CalendarWeekRule   myCWR         = myCI.DateTimeFormat.CalendarWeekRule;
            DayOfWeek          myFirstDOW    = myCI.DateTimeFormat.FirstDayOfWeek;

            var yearlyLookup = _joggings.ToLookup(j => j.JoggingDate.Year, j => j);
            int i            = 1;

            foreach (var gr in yearlyLookup.OrderBy(y => y.Key))
            {
                var weeklyLookup = gr.ToLookup(g => myCal.GetWeekOfYear(g.JoggingDate, myCWR, myFirstDOW), g => g);
                foreach (var week in weeklyLookup.OrderBy(w => w.Key))
                {
                    var weekSummary = GetWeekSummary(week.ToList());
                    weekSummary.WeekNumber = i;
                    weekSummaries.Add(weekSummary);
                    i++;
                }
            }

            return(PagedList <WeekSummary> .ToPagedList(weekSummaries, reportParameters.PageNumber, reportParameters.PageSize));
        }
        public void Page_Load(object sender, EventArgs e)
        {
            UserDetails user = new UserDetails();

            user = (UserDetails)Session["LoggedUser"];
            if (user == null)
            {
                Response.Redirect("Login.aspx");
            }
            dashboardID = int.Parse(Request.QueryString["id"]);
            List <Dashboard> dashboardlist = new List <Dashboard>();

            dashboardlist = user.UserDashboards.ToList();
            count         = dashboardlist.Count;
            Dashboard currentDashboard = new Dashboard();

            currentDashboard      = dashboardlist.Find(dash => dash.DashboardId == dashboardID);
            LblDashboardName.Text = currentDashboard.DashboardName;
            CalendarWeekRule weekRule     = CalendarWeekRule.FirstFourDayWeek;
            DayOfWeek        firstWeekDay = DayOfWeek.Monday;
            Calendar         calendar     = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;

            // currentWeek = calendar.GetWeekOfYear(DateTime.Now, weekRule, firstWeekDay);
            currentWeek = calendar.GetWeekOfYear(DateTime.Now, weekRule, firstWeekDay);
            UserID      = user.UserId;
            AccessRight = currentDashboard.UserAccessRight.AccessRightName;
            CompanyId   = user.CompanyId;
        }
示例#17
0
        // 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(
                          // TODO: SR
                          //nameof(firstDayOfWeek), SR.Format(SR.ArgumentOutOfRange_Range,
                          nameof(firstDayOfWeek), SR.Format("Valid values are between {0} and {1}, inclusive.",
                                                            DayOfWeek.Sunday, DayOfWeek.Saturday));
            }
            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(
                      // TODO: SR
                      //nameof(rule), SR.Format(SR.ArgumentOutOfRange_Range,
                      nameof(rule), SR.Format("Valid values are between {0} and {1}, inclusive.",
                                              CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
        }
示例#18
0
        private void InitializeControls()
        {
            int iYear = DateTime.Now.Year;

            for (int i = iYear; i <= iYear + 4; i++)
            {
                cmbxAnios.Items.Add(i.ToString());
            }
            cmbxAnios.Text = DateTime.Now.Year.ToString();

            //CALCULA Y LLENA EL NÚMERO TOTAL DE SEMANAS DEL AÑO
            cmbxSemanas.Items.Clear();
            DateTimeFormatInfo dfi   = DateTimeFormatInfo.CurrentInfo;
            DateTime           date1 = new DateTime(int.Parse(cmbxAnios.Text), 12, 31);
            Calendar           cal   = dfi.Calendar;

            for (int i = 1; i < cal.GetWeekOfYear(date1, dfi.CalendarWeekRule, dfi.FirstDayOfWeek) + 1; i++)
            {
                cmbxSemanas.Items.Add(i);
            }

            //CALCULAR EL NÚMERO DE SEMANA EN CURSO
            CultureInfo      _CultureInfo      = new CultureInfo("en-US");
            Calendar         _Calendar         = _CultureInfo.Calendar;
            CalendarWeekRule _CalendarWeekRule = _CultureInfo.DateTimeFormat.CalendarWeekRule;
            DayOfWeek        _DayOfWeek        = _CultureInfo.DateTimeFormat.FirstDayOfWeek;

            cmbxSemanas.Text = _Calendar.GetWeekOfYear(DateTime.Now, _CalendarWeekRule, _DayOfWeek).ToString();

            txtNoFactura.Focus();
        }
示例#19
0
        public void BclEquivalence(
            [ValueSource(typeof(BclCalendars), nameof(BclCalendars.MappedCalendars))] Calendar calendar,
            [ValueSource(nameof(CalendarWeekRules))] CalendarWeekRule bclRule,
            [ValueSource(nameof(BclDaysOfWeek))] DayOfWeek firstDayOfWeek)
        {
            var nodaCalendar = BclCalendars.CalendarSystemForCalendar(calendar) !;
            var nodaRule     = WeekYearRules.FromCalendarWeekRule(bclRule, firstDayOfWeek);
            var startYear    = new LocalDate(2016, 1, 1).WithCalendar(nodaCalendar).Year;

            for (int year = startYear; year < startYear + 30; year++)
            {
                var startDate = new LocalDate(year, 1, 1, nodaCalendar).PlusDays(-15);
                for (int day = 0; day < 30; day++)
                {
                    var date    = startDate.PlusDays(day);
                    var bclDate = date.ToDateTimeUnspecified();
                    var bclWeek = calendar.GetWeekOfYear(bclDate, bclRule, firstDayOfWeek);
                    // Weird... the BCL doesn't have a way of finding out which week-year we're in.
                    // We're starting at "start of year - 15 days", so a "small" week-of-year
                    // value means we're in "year", whereas a "large" week-of-year value means
                    // we're in the "year-1".
                    var bclWeekYear = bclWeek < 10 ? year : year - 1;

                    Assert.AreEqual(bclWeek, nodaRule.GetWeekOfWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(bclWeekYear, nodaRule.GetWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(date, nodaRule.GetLocalDate(bclWeekYear, bclWeek, date.DayOfWeek, nodaCalendar),
                                    "Week-year:{0}; Week: {1}; Day: {2}", bclWeekYear, bclWeek, date.DayOfWeek);
                }
            }
        }
示例#20
0
        public void CalendarWeekRule_Set_GetReturnsExpected(CalendarWeekRule value)
        {
            var format = new DateTimeFormatInfo();

            format.CalendarWeekRule = value;
            Assert.Equal(value, format.CalendarWeekRule);
        }
 internal DateTimeFormatInfo(StreamReader s, string calendarName)
 {
     char[] comma = new char[] { ',' };
     this.abbreviatedDayNames = s.ReadLine().Split(comma);
     this.abbreviatedMonthGenitiveNames = s.ReadLine().Split(comma);
     this.abbreviatedMonthNames = s.ReadLine().Split(comma);
     this.amDesignator = s.ReadLine();
     this.calendarWeekRule = (CalendarWeekRule)int.Parse(s.ReadLine());
     this.dateSeparator = s.ReadLine();
     this.dayNames = s.ReadLine().Split(comma);
     this.firstDayOfWeek = (DayOfWeek)int.Parse(s.ReadLine());
     this.fullDateTimePattern = s.ReadLine();
     this.longDatePattern = s.ReadLine();
     this.longTimePattern = s.ReadLine();
     this.monthDayPattern = s.ReadLine();
     this.monthGenitiveNames = s.ReadLine().Split(comma);
     this.monthNames = s.ReadLine().Split(comma);
     this.nativeCalendarName = s.ReadLine();
     s.ReadLine(); // TODO: Appears to be a mistake in the culture files. Extra line added.
     this.pmDesignator = s.ReadLine();
     this.rfc1123Pattern = s.ReadLine(); // This is always the same, so does it need to be in the culture file?
     this.shortDatePattern = s.ReadLine();
     this.shortestDayNames = s.ReadLine().Split(comma);
     this.shortTimePattern = s.ReadLine();
     this.sortableDateTimePattern = s.ReadLine(); // This is always the same
     this.timeSeparator = s.ReadLine();
     this.universalSortableDateTimePattern = s.ReadLine(); // This is always the same
     this.yearMonthPattern = s.ReadLine();
     this.calendar = Calendar.CreateByName(calendarName);
 }
示例#22
0
 static DataService()
 {
     Barrel.ApplicationId = AppInfo.PackageName;
     barrel     = Barrel.Create(FileSystem.AppDataDirectory);
     myCI       = new CultureInfo("en-US");
     myCWR      = myCI.DateTimeFormat.CalendarWeekRule;
     myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
 }
        public void GetLocalDate_Invalid(
            CalendarWeekRule bclRule, DayOfWeek firstDayOfWeek,
            int weekYear, int week, IsoDayOfWeek dayOfWeek)
        {
            var nodaRule = WeekYearRules.FromCalendarWeekRule(bclRule, firstDayOfWeek);

            Assert.Throws <ArgumentOutOfRangeException>(() => nodaRule.GetLocalDate(weekYear, week, dayOfWeek));
        }
示例#24
0
        /// <summary>
        /// Returns the Week of a specific DateTime and Culture
        /// </summary>
        /// <param name="dt">The datetime</param>
        /// <param name="ci">The culture</param>
        /// <returns>An integer value with the week</returns>
        public static int GetWeekOfDate(DateTime dt, CultureInfo ci)
        {
            Calendar         calendar         = ci.Calendar;
            CalendarWeekRule calendarweekrule = ci.DateTimeFormat.CalendarWeekRule;
            DayOfWeek        firstdayofweek   = ci.DateTimeFormat.FirstDayOfWeek;

            return(calendar.GetWeekOfYear(dt, calendarweekrule, firstdayofweek));
        }
示例#25
0
        public static void GetWeekInYear()
        {
            CultureInfo      myCI  = new CultureInfo("vi-VN");
            Calendar         myCal = myCI.Calendar;
            CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

            CurrentWeekOfYear = myCal.GetWeekOfYear(DateTime.Now, myCWR, DayOfWeek.Monday);
        }
示例#26
0
        public static IList <Week> GetWeeks(int year, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
        {
            var from  = new DateTime(year, 1, 1);
            var to    = new DateTime(year, 12, 31);
            var weeks = GetWeeks(from, to, rule, firstDayOfWeek);

            return(weeks.Where(w => w.Year == year).ToList());
        }
示例#27
0
        /// <summary>
        /// 取得本周在一年中的周数
        /// </summary>
        /// <returns></returns>
        public static int GetThisWeekNo()
        {
            CultureInfo      myCI  = new CultureInfo("en-US");
            Calendar         myCal = myCI.Calendar;
            CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

            return(myCal.GetWeekOfYear(DateTime.Now, myCWR, DayOfWeek.Sunday));
        }
示例#28
0
 public static int WeekOfYear(this DateTime value, CalendarWeekRule rule = CalendarWeekRule.FirstDay, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
 {
     return(CultureInfo
            .CurrentCulture
            .DateTimeFormat
            .Calendar
            .GetWeekOfYear(value, rule, firstDayOfWeek));
 }
 /// <summary>
 /// lấy ra tuần theo ngày hiện tại
 /// </summary>
 /// <param name="time"></param>
 /// <returns></returns>
 public static int GetWeekOrderInYear(DateTime time)
 {
     CultureInfo myCI = CultureInfo.CurrentCulture;
     System.Globalization.Calendar myCal = myCI.Calendar;
     CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
     DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
     return myCal.GetWeekOfYear(time, myCWR, myFirstDOW);
 }
        public void TestLocaleFirstDay()
        {
            CultureInfo        myTestCulture = new CultureInfo("en-US");
            DateTimeFormatInfo dti           = myTestCulture.DateTimeFormat;
            CalendarWeekRule   actual        = dti.CalendarWeekRule;

            Assert.Equal(CalendarWeekRule.FirstDay, actual);
        }
        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);
        }
示例#32
0
        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);;
        }
        /// <summary>
        /// Indicates whether the given date is in even week or not.
        /// </summary>
        /// <param name="dt">The date</param>
        /// <returns>A boolean value represents whether the given date is in even week or not</returns>
        public static bool IsEvenWeek(DateTime dt)
        {
            CultureInfo      culture          = new CultureInfo("de-DE");
            Calendar         calendar         = culture.Calendar;
            CalendarWeekRule calendarWeekRule = culture.DateTimeFormat.CalendarWeekRule;
            DayOfWeek        FirstDayOfWeek   = culture.DateTimeFormat.FirstDayOfWeek;

            return(calendar.GetWeekOfYear(dt, calendarWeekRule, FirstDayOfWeek) % 2 == 0);
        }
        //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);
        }
        private void VerificationHelper(DateTimeFormatInfo info, CalendarWeekRule expected, bool setter)
        {
            if (setter)
            {
                info.CalendarWeekRule = expected;
            }

            CalendarWeekRule actual = info.CalendarWeekRule;
            Assert.Equal(expected, actual);
        }
示例#36
0
        /// <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);
        }
示例#37
0
        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);
        }
        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);
        }
        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;;
        }
示例#40
0
        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);
        }
示例#41
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);
        }
 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));
 }
示例#43
0
文件: Main.cs 项目: dosjos/VinLotteri
        //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();
        }
        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;
        }
示例#45
0
 /// <summary>
 /// Returns the week of the year that includes the date in the specified DateTime value.
 /// </summary>
 /// <param name="time">A date and time value.</param>
 /// <param name="rule">An enumeration value that defines a calendar week.</param>
 /// <param name="firstDayOfWeek">An enumeration value that represents the first day of the week.</param>
 /// <returns>A positive integer that represents the week of the year
 /// that includes the date in the <paramref name="time"/> parameter.</returns>
 public static int GetWeekOfYear(this DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(time, rule, firstDayOfWeek);
 }
示例#46
0
 /// <summary>
 /// Returns the week of the year that includes the date in the specified DateTime value.
 /// </summary>
 /// <param name="time">A date and time value.</param>
 /// <param name="rule">An enumeration value that defines a calendar week.</param>
 /// <returns>A positive integer that represents the week of the year
 /// that includes the date in the <paramref name="time"/> parameter.</returns>
 public static int GetWeekOfYear(this DateTime time, CalendarWeekRule rule)
 {
     return GetWeekOfYear(time, rule, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
 }
示例#47
0
        // ----------------------------------------------------------------------
        public static bool IsSameWeek( DateTime left, DateTime right, CultureInfo culture, 
			CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek, YearWeekType weekType )
        {
            if ( culture == null )
            {
                throw new ArgumentNullException( "culture" );
            }

            // left
            int leftWeekOfYear;
            int leftYear;
            TimeTool.GetWeekOfYear( left, culture, weekRule, firstDayOfWeek, weekType, out leftYear, out leftWeekOfYear );

            // rught
            int rightWeekOfYear;
            int rightYear;
            TimeTool.GetWeekOfYear( right, culture, weekRule, firstDayOfWeek, weekType, out rightYear, out rightWeekOfYear );

            return leftYear == rightYear && leftWeekOfYear == rightWeekOfYear;
        }
示例#48
0
 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));
 }
示例#49
0
        // 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));
        }
 public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
   return default(int);
 }
示例#51
0
 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);
 }
示例#52
0
        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 }));
        }
示例#53
0
	/// <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;
	}
示例#54
0
	/// <summary>
	/// A protected method that gives the first day of the second week of
	/// the year.
	/// </summary>
	/// <param name="year">An integer that represents the year.</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>The <see cref="T:System.DateTime"/> representing 
	/// the first day of the second week of the year.
	/// </returns>
	internal DateTime M_GetFirstDayOfSecondWeekOfYear(
		int year, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
	{
		DateTime d1 = ToDateTime(year, 1, 1, 0, 0, 0, 0);
		int dow1 = (int)GetDayOfWeek(d1);
		int fdow = (int)firstDayOfWeek;
		int d = 0;

		switch (rule) {
		case CalendarWeekRule.FirstDay:
			if (fdow > dow1) {
				d += fdow - dow1;
			}
			else {
				d += fdow + M_DaysInWeek - dow1;
			}
			break;
		case CalendarWeekRule.FirstFullWeek:
			d = M_DaysInWeek;
			if (fdow >= dow1) {
				d += fdow - dow1;
			}
			else {
				d += fdow + M_DaysInWeek - dow1;
			}
			break;
		case CalendarWeekRule.FirstFourDayWeek:
			int dow4 = (dow1 + 3)%M_DaysInWeek;

			d = 3;
			if (fdow > dow4) {
				d += fdow - dow4;
			}
			else {
				d += fdow + M_DaysInWeek - dow4;
			}
			break;
		}

		return AddDays(d1, d);
	}
	public virtual int GetWeekOfYear(System.DateTime time, CalendarWeekRule rule, System.DayOfWeek firstDayOfWeek) {}
 private void ExecutePosTest(string errorNum1, string errorNum2, Calendar myCalendar, int year,
     int month, int day, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     DateTime time;
     int actualDayOfYear, expectedDayOfYear;
     int weekOfYear;
     time = myCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
     expectedDayOfYear = myCalendar.GetDayOfYear(time);
     weekOfYear = myCalendar.GetWeekOfYear(time, rule, firstDayOfWeek);
     actualDayOfYear = this.GetDayOfYear(time, rule, firstDayOfWeek, weekOfYear, myCalendar);
     Assert.Equal(expectedDayOfYear, actualDayOfYear);
 }
 //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;
 }
示例#58
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);
        }
 public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     return (helper.GetWeekOfYear(time, rule, firstDayOfWeek));
 }
示例#60
0
        private static int GCWeekOfYear(DateTime date, CalendarWeekRule rule, DayOfWeek firstDayOfWeek = (DayOfWeek)(-1))
        {
            if (firstDayOfWeek == (DayOfWeek)(-1))
            {
                firstDayOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
            }

            GregorianCalendar gc = new GregorianCalendar(GregorianCalendarTypes.Localized);
            return gc.GetWeekOfYear(date, rule, firstDayOfWeek);
        }