public void GetDaysInMonthShouldReturnCorrectCount() { var target = new GregorianFiscalCalendar( 7 ); var calendar = new GregorianCalendar(); Assert.Equal( calendar.GetDaysInMonth( 2010, 7 ), target.GetDaysInMonth( 2011, 1 ) ); Assert.Equal( calendar.GetDaysInMonth( 2010, 8 ), target.GetDaysInMonth( 2011, 2 ) ); Assert.Equal( calendar.GetDaysInMonth( 2010, 6 ), target.GetDaysInMonth( 2010, 12 ) ); Assert.Equal( calendar.GetDaysInMonth( 2011, 6 ), target.GetDaysInMonth( 2011, 12 ) ); }
public WorkMonth(int year, int month, GermanSpecialDays specialDays, IEnumerable<ShortCut> shortCuts, float hoursPerDay) { this.year = year; this.month = month; this.hoursPerDay = hoursPerDay; this.Weeks = new ObservableCollection<WorkWeek>(); this.Days = new ObservableCollection<WorkDay>(); this.ShortCutStatistic = new ObservableCollection<KeyValuePair<string, ShortCutStatistic>>(); // TODO which date should i take? this.ReloadShortcutStatistic(shortCuts); var cal = new GregorianCalendar(); WorkWeek lastWeek = null; for (int day = 1; day <= cal.GetDaysInMonth(year, month); day++) { var dt = new DateTime(year, month, day); WorkDay wd = new WorkDay(year, month, day, specialDays); this.Days.Add(wd); var weekOfYear = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday); if (lastWeek == null || lastWeek.WeekOfYear != weekOfYear) { lastWeek = new WorkWeek(this, weekOfYear); lastWeek.PropertyChanged += new PropertyChangedEventHandler(this.WeekPropertyChanged); this.Weeks.Add(lastWeek); } lastWeek.AddDay(wd); } }
public static List<ActivityDay> GetCalendarDaysFor(int? period/*0=yearly, 1=monthly and 2=weekly*/) { var days = new List<ActivityDay>(); //var calendar = new ActivityCalendar(); var calendarYear = new GregorianCalendar(); switch (period) { case 0: var dayNumber=(int)DateTime.Now.DayOfWeek; var weekDay = DateTime.Now.AddDays(-dayNumber); for (int i=0;i<7;i++) { days.Add(new ActivityDay { Date = weekDay, Name = calendarYear.GetDayOfWeek(weekDay).ToString(), Status=true, ActivityStatus = calendarYear.GetDayOfWeek(weekDay) == DayOfWeek.Friday ? DayStatus.Holiday :DayStatus.Active}); weekDay=weekDay.AddDays(1); } break; case 1: var daysInMonth=calendarYear.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month); for (int day = 1; day <= daysInMonth;day++ ) { var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day); days.Add(new ActivityDay { Date = date, Name = calendarYear.GetDayOfWeek(date).ToString(), Status = true, ActivityStatus = calendarYear.GetDayOfWeek(date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active }); } break; default: var daysInYr=calendarYear.GetDaysInYear(DateTime.Now.Year); var startOfYr = new DateTime(DateTime.Now.Year, 1, 1); for (int day = 0; day < daysInYr; day++) { var dateOfYr = new ActivityDay {Date=startOfYr.AddDays(day) }; dateOfYr.Name = calendarYear.GetDayOfWeek(dateOfYr.Date).ToString(); dateOfYr.Status = true; dateOfYr.ActivityStatus = calendarYear.GetDayOfWeek(dateOfYr.Date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active; days.Add(dateOfYr); } break; } return days; }
public void PosTest3() { System.Globalization.Calendar kC = new KoreanCalendar(); System.Globalization.Calendar gC = new GregorianCalendar(); DateTime dateTime = new GregorianCalendar().ToDateTime(2004, 2, 29, 0, 0, 0, 0); int expectedValue = gC.GetDaysInMonth(dateTime.Year, dateTime.Month, gC.GetEra(dateTime)); int actualValue; actualValue = kC.GetDaysInMonth(dateTime.Year + 2333, dateTime.Month, kC.GetEra(dateTime)); Assert.Equal(expectedValue, actualValue); }
/// <summary> /// Query if <paramref name="date"/> is the last occurrence of that particulay day of the week for the month that <paramref name="date"/> /// occurs. /// </summary> /// <param name="date">date</param> /// <returns>true if last occurrence, else false</returns> public static bool IsLastOccurrenceOfDayInMonth(this DateTime date) { date = date.Date; System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); DateTime lastOfMonth = new DateTime(date.Year, date.Month, calendar.GetDaysInMonth(date.Year, date.Month)); TimeSpan daysFromLastOfMonth = lastOfMonth - date; return(daysFromLastOfMonth.Days < 7); }
public void PosTest3() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; int expectedDays, actualDays; year = GetACommonYear(myCalendar); month = 2; expectedDays = s_daysInMonth365[month]; actualDays = myCalendar.GetDaysInMonth(year, month); Assert.Equal(expectedDays, actualDays); }
public void PosTest4() { System.Globalization.Calendar kC = new KoreanCalendar(); System.Globalization.Calendar gC = new GregorianCalendar(); DateTime dateTime = new DateTime(_generator.GetInt64(-55) % (DateTime.MaxValue.Ticks + 1)); dateTime = new GregorianCalendar().ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0); int month = _generator.GetInt16(-55) % 12 + 1; int expectedValue = gC.GetDaysInMonth(dateTime.Year, month, gC.GetEra(dateTime)); int actualValue; actualValue = kC.GetDaysInMonth(dateTime.Year + 2333, month, kC.GetEra(dateTime)); Assert.Equal(expectedValue, actualValue); }
public void PosTest4() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; int expectedDays, actualDays; year = GetACommonYear(myCalendar); //Get a random value beween 1 and 12 not including 2. do { month = TestLibrary.Generator.GetInt32(-55) % 12 + 1; } while (2 == month); expectedDays = s_daysInMonth365[month]; actualDays = myCalendar.GetDaysInMonth(year, month); Assert.Equal(expectedDays, actualDays); }
/// <summary> /// Gets the number of the given weekday in the days past in the month of the given date /// </summary> public static int GetNumberOfWeekdaysInDaysPast(DateTime date, DayOfWeek day) { var nWeekdays = 0; var calendar = new GregorianCalendar(); var daysInMonth = calendar.GetDaysInMonth(date.Year, date.Month); var tempDate = GetStartOfMonth(date); for (int i = 1; i <= date.Day; i++, tempDate = tempDate.AddDays(1)) { if (tempDate.DayOfWeek == DayOfWeek.Sunday) { nWeekdays++; } } return nWeekdays; }
/// <summary> /// 取得当前系统月份的天,参考时区 /// </summary> /// <returns></returns> public static int getCurMonthDays(float timezone) { GregorianCalendar gc = new GregorianCalendar(); DateTime dt = curDateWithTimeZone(timezone); return gc.GetDaysInMonth(dt.Year, dt.Month); }
public void PosTest5() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; int expectedDays, actualDays; year = myCalendar.MaxSupportedDateTime.Year; //Get a random month whose value is beween 1 and 12 month = _generator.GetInt32(-55) % 12 + 1; expectedDays = (IsLeapYear(year)) ? s_daysInMonth366[month] : s_daysInMonth365[month]; actualDays = myCalendar.GetDaysInMonth(year, month); Assert.Equal(expectedDays, actualDays); }
public void PosTest9() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; int expectedDays, actualDays; year = myCalendar.MaxSupportedDateTime.Year; month = 12; expectedDays = (IsLeapYear(year)) ? s_daysInMonth366[month] : s_daysInMonth365[month]; actualDays = myCalendar.GetDaysInMonth(year, month); Assert.Equal(expectedDays, actualDays); }
/// <summary> /// 获得某年某月的天数(命名空间System.Globalization) /// </summary> /// <returns></returns> public static int GetDay() { GregorianCalendar gc = new GregorianCalendar(); return gc.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month); }
public void NegTest4() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; year = myCalendar.MinSupportedDateTime.Year - 100; month = -1 * _generator.GetInt32(-55); Assert.Throws<ArgumentOutOfRangeException>(() => { myCalendar.GetDaysInMonth(year, month); }); }
public void NegTest3() { System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); int year, month; year = GetAYear(myCalendar); month = 13 + _generator.GetInt32(-55) % (int.MaxValue - 12); Assert.Throws<ArgumentOutOfRangeException>(() => { myCalendar.GetDaysInMonth(year, month); }); }
// This adds a recurring item to the list as many times as needed (and with proper dates) private void AddRecurringItem(ICollection<AgendaItem> list, AgendaItem item, DateTime from, DateTime to) { GregorianCalendar calendar = new GregorianCalendar(); TimeSpan alarmoffset = item.startdate - item.alarmdate; DateTime d = from; // Advance d to the first occurence of the item within this time period switch(item.recur) { case AgendaItemRecur.Weekly: if((int)d.DayOfWeek < (int)item.startdate.DayOfWeek) d = d.AddDays((int)item.startdate.DayOfWeek - (int)d.DayOfWeek); else if((int)d.DayOfWeek > (int)item.startdate.DayOfWeek) d = d.AddDays((7 - (int)d.DayOfWeek) + (int)item.startdate.DayOfWeek); break; case AgendaItemRecur.Monthly: if(d.Day < item.startdate.Day) d = d.AddDays(item.startdate.Day - d.Day); else if(d.Day > item.startdate.Day) d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day); break; case AgendaItemRecur.Annually: // First advance to the correct day in the month // so that we don't skip over the day when advancing by months if(d.Day < item.startdate.Day) d = d.AddDays(item.startdate.Day - d.Day); else if(d.Day > item.startdate.Day) d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day); // Now advance by months if(d.Month < item.startdate.Month) d = d.AddMonths(item.startdate.Month - d.Month); else if(d.Month > item.startdate.Month) d = d.AddMonths((12 - d.Month) + item.startdate.Month); break; } // We check how many times we can repeat the item within the // given timespan and add the item repeatedly while(d.Ticks <= to.Ticks) { // Add item with proper dates AgendaItem newitem = item; newitem.startdate = d.AddHours(item.startdate.Hour).AddMinutes(item.startdate.Minute); newitem.alarmdate = newitem.startdate.Subtract(alarmoffset); TimeSpan span = newitem.startdate - newitem.originstartdate; switch(item.recur) { case AgendaItemRecur.Weekly: newitem.recursions = (int)Math.Round(span.TotalDays / 7.0d); break; case AgendaItemRecur.Monthly: newitem.recursions = (int)Math.Round(span.TotalDays / 30.4375d); break; case AgendaItemRecur.Annually: newitem.recursions = (int)Math.Round(span.TotalDays / 365.25d); break; } list.Add(newitem); // Advance date to the next date when the item recurs switch(item.recur) { case AgendaItemRecur.Weekly: d = d.AddDays(7); break; case AgendaItemRecur.Monthly: //d = d.AddDays(calendar.GetDaysInMonth(d.Year, d.Month)); d = d.AddMonths(1); break; case AgendaItemRecur.Annually: d = d.AddYears(1); break; } } }
/// <summary> /// 取得某个年月的天数 /// </summary> /// <returns></returns> public static int getMonthDays(int year, int month) { GregorianCalendar gc = new GregorianCalendar(); return gc.GetDaysInMonth(year, month); }
public static int GetNumberOfDaysInMonth(DateTime date) { var calendar = new GregorianCalendar(); return calendar.GetDaysInMonth(date.Year, date.Month); }
private void GetGregDateScope() { gCal = new GregorianCalendar(); int _currentGregMonthLength = gCal.GetDaysInMonth(CurrentGregYear, CurrentGregMonth); //int[] _scope = new int[7]; if ((CurrentGregDay + 6) > _currentGregMonthLength) { //if next month if ((CurrentGregMonth + 1) > 12) { //if next year NextGregMonth = 1; NextGregYear = CurrentGregYear + 1; } else NextGregMonth = CurrentGregMonth + 1; //create new dates scope int[] _scopeInCurrentMonth = Enumerable.Range(CurrentGregDay, (_currentGregMonthLength - CurrentGregDay + 1)).ToArray(); int[] _scopeInNextMonth = Enumerable.Range(1, (Math.Abs(_currentGregMonthLength - (CurrentGregDay + 6)))).ToArray(); //_scopeInCurrentMonth.CopyTo(_scope, 0); //_scopeInNextMonth.CopyTo(_scope, _scopeInCurrentMonth.Length); CurrentGregDayScope = _scopeInCurrentMonth; NextGregMonthScope = _scopeInNextMonth; } else { //if current month //_scope = Enumerable.Range( CurrentGregDay, 7 ).ToArray(); CurrentGregDayScope = Enumerable.Range( CurrentGregDay, 7 ).ToArray(); } //return _scope; }
private void bb_mes_Click(object sender, EventArgs e) { month = 0; if (((Button)sender).Text.ToUpper().Equals("JANEIRO")) { month = 01; } else if (((Button)sender).Text.ToUpper().Equals("FEVEREIRO")) { month = 02; } else if (((Button)sender).Text.ToUpper().Equals("MARÇO")) { month = 03; } else if (((Button)sender).Text.ToUpper().Equals("ABRIL")) { month = 04; } else if (((Button)sender).Text.ToUpper().Equals("MAIO")) { month = 05; } else if (((Button)sender).Text.ToUpper().Equals("JUNHO")) { month = 06; } else if (((Button)sender).Text.ToUpper().Equals("JULHO")) { month = 07; } else if (((Button)sender).Text.ToUpper().Equals("AGOSTO")) { month = 08; } else if (((Button)sender).Text.ToUpper().Equals("SETEMBRO")) { month = 09; } else if (((Button)sender).Text.ToUpper().Equals("OUTUBRO")) { month = 10; } else if (((Button)sender).Text.ToUpper().Equals("NOVEMBRO")) { month = 11; } else if (((Button)sender).Text.ToUpper().Equals("DEZEMBRO")) { month = 12; } // obtém a quantidade de dias MÊS e ANO selecionados System.Globalization.Calendar c = new System.Globalization.GregorianCalendar(); daysMonth = c.GetDaysInMonth(int.Parse(cbxAno.SelectedItem.ToString()), month); //Verificar dia da semana em que se incia o MÊS selecionado DateTime date; date = Convert.ToDateTime("01" + "/" + month.ToString() + "/" + cbxAno.SelectedItem.ToString()); string day = date.DayOfWeek.ToString(); //Chamar Mes tcPainel.TabPages.Remove(tpAno); tcPainel.TabPages.Add(tpMes); //Preencher Mudança this.PreencherMudanca(date); //Preencher mes this.LimparLabel(); this.PreencherMes(day); //Layout Mes tpMes.Text = ((Button)sender).Text + "/" + cbxAno.SelectedItem.ToString() + " - " + lCfg[0].Nm_empresa + " LEGENDA: I - INICIO VIAGEM[PRETO]| V - EM VIAGEM[AZUL]| E - ENTREGA[VERDE]| [Pressione ESC para Sair]."; tpMes.Font = new Font("Arial", 15, FontStyle.Bold); tpMes.ForeColor = Color.Blue; //Redimensionar se mes nao ocupar todos os ListBox if (lb29.Items.Count.Equals(0) && lb30.Items.Count.Equals(0) && lb31.Items.Count.Equals(0) && lb32.Items.Count.Equals(0) && lb33.Items.Count.Equals(0) && lb34.Items.Count.Equals(0) && lb35.Items.Count.Equals(0)) { tlpMes.RowStyles[5] = new RowStyle(SizeType.Absolute, 0); } else { tlpMes.RowStyles[5] = new RowStyle(SizeType.Percent, 16.67067F); } //Redimensionar se mes nao ocupar todos os ListBox if (lb36.Items.Count.Equals(0) && lb37.Items.Count.Equals(0)) { tlpMes.RowStyles[6] = new RowStyle(SizeType.Absolute, 0); } else { tlpMes.RowStyles[6] = new RowStyle(SizeType.Percent, 16.67067F); } }