public void IsHolidayCanHandleSingleYear() { var startYear = 2000; var howManyYears = 1; var newYears2000 = new DateTime(startYear, 1, 1); var newYears2001 = new DateTime(startYear + 1, 1, 1); var newYears1999 = new DateTime(startYear - 1, 1, 1); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(newYears2000)); Assert.IsFalse(sut.IsHoliday(newYears2001)); Assert.IsFalse(sut.IsHoliday(newYears1999)); }
public void AddRange(List <SwapableList> s) { dgViewSwap.Columns.Clear(); dgViewSwap.Columns.Add("医師名", "医師名"); dgViewSwap.Columns.Add("日付", "日付"); dgViewSwap.Columns.Add("コメント", "コメント"); dgViewSwap.Columns[2].Width = 200; var row = new DataGridViewRow[s.Count]; for (int i = 0; i < s.Count; i++) { row[i] = new DataGridViewRow(); row[i].CreateCells(dgViewSwap); row[i].Cells[0].Value = s[i].Person; row[i].Cells[1].Value = s[i].Day + "日"; row[i].Cells[1].Tag = s[i].Day; if (HolidayChecker.IsHoliday(Date) && HolidayChecker.IsHoliday(new DateTime(Date.Year, Date.Month, s[i].Day))) { row[i].DefaultCellStyle.ForeColor = Color.Red; row[i].Cells[2].Value = "休日同士の交代です"; } else if (!HolidayChecker.IsHoliday(Date) && !HolidayChecker.IsHoliday(new DateTime(Date.Year, Date.Month, s[i].Day))) { row[i].DefaultCellStyle.ForeColor = Color.Blue; row[i].Cells[2].Value = "平日同士の交代です"; } else { row[i].DefaultCellStyle.ForeColor = Color.Gray; row[i].Cells[2].Value = "休日と平日の交代です"; } } dgViewSwap.Rows.AddRange(row); }
public Dictionary <IEmployeePresentationData, double> Calculate(ISchedule schedule) { Dictionary <IEmployeePresentationData, double> output = new Dictionary <IEmployeePresentationData, double>(); foreach (IEmployee employee in schedule.Employees) { int i = 0; double numberOfHours = 0; schedule.IterateOverAllDays((date) => { IWorkingOption planForDay = employee.WorkingPlan[i++]; // This is a night if (planForDay.Symbol == "N") { // This is not a holiday but the next day is if (!HolidayChecker.IsHoliday(date) && HolidayChecker.IsHoliday(date.AddDays(1))) { numberOfHours += HoursFoNightFromNotHolidayToHoliday; } // This is a holiday else if (HolidayChecker.IsHoliday(date)) { numberOfHours += HoursForHolidayNight; } } }); output.Add(employee, numberOfHours); } return(output); }
private HomeViewModel BuildHomeViewModel(DateTime date) { HomeViewModel model = new HomeViewModel(); DateTime baseTime = new DateTime(date.Year, date.Month, date.Day, 9, 0, 0); List <Appointment> appointments = _service.FindAppointments(date).ToList(); List <AppUser> mechanics = _service.Mechanics.ToList(); Dictionary <int, int> columns = new Dictionary <int, int>(); foreach (AppUser m in mechanics) { columns.Add(m.Id, mechanics.IndexOf(m)); } model.Date = date; model.Mechanics = mechanics.Select(m => m.Name).ToList(); for (int i = 0; i < 8; ++i) { foreach (AppUser m in mechanics) { DateTime start = baseTime.AddHours(i); TimeslotViewModel item = new TimeslotViewModel(start, m.Id, m.Name); model.Timeslots[i].Add(item); } } foreach (Appointment appointment in appointments) { TimeslotStatus status; if (appointment.Partner.UserName.Equals(User.Identity.Name)) { status = TimeslotStatus.OWN; model.Timeslots[appointment.Time.Hour - 9][columns.GetValueOrDefault(appointment.Mechanic.Id)].Id = appointment.Id; } else { status = TimeslotStatus.BOOKED; } model.Timeslots[appointment.Time.Hour - 9][columns.GetValueOrDefault(appointment.Mechanic.Id)].Status = status; } for (int i = 0; i < 8; ++i) { foreach (AppUser m in mechanics) { TimeslotViewModel timeslot = model.Timeslots[i][columns.GetValueOrDefault(m.Id)]; if (timeslot.Start < DateTime.Now || HolidayChecker.IsHoliday(timeslot.Start)) { timeslot.Status = TimeslotStatus.DISABLED; } } } return(model); }
public void IsHolidayCanHandleFourthOfJuly() { var startYear = 2014; var howManyYears = 1; var fourthOfJuly = new DateTime(startYear, 7, 4); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(fourthOfJuly)); }
public void IsHolidayCanHandleNewYears() { var startYear = 2010; var howManyYears = 1; var newYears2000 = new DateTime(startYear, 1, 1); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(newYears2000)); }
public void IsHolidayCanHandleMultipleYears() { var startYear = 2000; var howManyYears = 3; var newYears2000 = new DateTime(startYear, 1, 1); var newYears2001 = new DateTime(startYear + 1, 1, 1); var newYears2002 = new DateTime(startYear + 2, 1, 1); var newYears2003 = new DateTime(startYear + 3, 1, 1); var newYears1999 = new DateTime(startYear - 1, 1, 1); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(newYears2000)); Assert.IsTrue(sut.IsHoliday(newYears2001)); Assert.IsTrue(sut.IsHoliday(newYears2002)); Assert.IsFalse(sut.IsHoliday(newYears2003)); Assert.IsFalse(sut.IsHoliday(newYears1999)); }
public void IsHolidayWillBeFalseWhenZeroYearsAreSpecified() { var startYear = 2000; var howManyYears = 0; var date = new DateTime(startYear, 1, 1); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsFalse(sut.IsHoliday(date)); }
public void IsHolidayCanHandleThanksgiving() { var startYear = 2020; var howManyYears = 1; var thanksgiving = new DateTime(startYear, 11, 26); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(thanksgiving)); }
public void IsHolidayCanHandleLaborDay() { var startYear = 2025; var howManyYears = 1; var laborDay = new DateTime(startYear, 9, 1); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(laborDay)); }
public void IsHolidayCanHandleMemorialDay() { var startYear = 2030; var howManyYears = 1; var memorialDay = new DateTime(startYear, 5, 27); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(memorialDay)); }
public void IsHolidayCanHandleChristmas() { var startYear = 1980; var howManyYears = 1; var christmas = new DateTime(startYear, 12, 25); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsTrue(sut.IsHoliday(christmas)); }
public void IsHolidayWillBeFalseWhenNotAHoliday() { var startYear = 2000; var howManyYears = 1; var date = new DateTime(startYear, 1, 2); var sut = new HolidayChecker(startYear, howManyYears); Assert.IsFalse(sut.IsHoliday(date)); }