public void ContainsDate()
        {
            var range = new DateRange(this.date1900, this.date2000);

            Assert.AreEqual(this.date1900, range.Start, "Start");
            Assert.AreEqual(this.date2000, range.Finish, "Finish");

            Assert.IsTrue(range.Contains(this.date1900), "1900");
            Assert.IsTrue(range.Contains(this.date1950), "1950");
            Assert.IsTrue(range.Contains(this.date2000), "2000");
        }
예제 #2
0
        public void TestMethod1()
        {
            var      michaelMassTerm = new DateRange(new DateTime(2016, 9, 8), 1);
            DateTime a = new DateTime(2016, 6, 7);

            Assert.IsFalse(michaelMassTerm.Contains(a));
        }
예제 #3
0
        public List <Weather> GetWeather(DateRange dateRange, Location location)
        {
            var url = string.Format(ApiUri, location.Latitude, location.Longitude);

            var response = WebRequest.Create(url).GetResponse();
            var json     = JsonConvert.DeserializeObject <WeatherResponse>(new StreamReader(response.GetResponseStream()).ReadToEnd());
            var result   = new List <Weather>();

            foreach (var item in json.list)
            {
                var date = DateTimeHelpers.FromTimeStamp(item.dt);
                if (dateRange.Contains(date.Date))
                {
                    var weather = new Weather
                    {
                        Cloudness     = item.clouds,
                        Date          = date.Date,
                        Temperature   = (item.temp.max + item.temp.min) / 2 - 273.15, //Take average and convert from Kelvin to Celsius
                        Precipitation = GetPrecipitation(item.weather.Select(w => w.id))
                    };

                    result.Add(weather);
                }
            }

            return(result);
        }
        public void ContainsRange()
        {
            var first  = new DateRange(this.date1900, this.date2000);
            var second = new DateRange(this.date1950, this.date1950);

            Assert.IsTrue(first.Contains(second));
        }
        public void NotContainsRange()
        {
            var first  = new DateRange(this.date1900, this.date2000);
            var second = new DateRange(this.date1900.AddDays(-1), this.date1950);

            Assert.IsFalse(first.Contains(second));
        }
예제 #6
0
        public bool ShouldReturnIsDateRangeContainsDateTime(DateRange dateRange, DateTime dateTime)
        {
            // when
            var contains = dateRange.Contains(dateTime);

            // then
            return(contains);
        }
예제 #7
0
        public void Contains_IsFalse()
        {
            var target = new DateRange(Dates.January(1, 2000), Dates.December(31, 2000));

            var actual = target.Contains(Dates.March(4, 2001));

            actual.Should().BeFalse();
        }
예제 #8
0
        public void BeforeRange()
        {
            var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 01, 31));

            var testDate = new Date(1999, 12, 07);
            var result   = dateRange.Contains(testDate);

            result.Should().BeFalse();
        }
예제 #9
0
        public void LastDayOfRange()
        {
            var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 01, 31));

            var testDate = new Date(2000, 01, 31);
            var result   = dateRange.Contains(testDate);

            result.Should().BeTrue();
        }
예제 #10
0
        public void AfterRange()
        {
            var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 01, 31));

            var testDate = new Date(2002, 03, 01);
            var result   = dateRange.Contains(testDate);

            result.Should().BeFalse();
        }
예제 #11
0
        public void DateRangeExtensions_Contains_DateNotInDateRange_ReturnsFalse()
        {
            var dateRange = new DateRange(new DateTime(2017, 1, 1), new DateTime(2017, 2, 1));
            var dateTime  = new DateTime(1990, 1, 15);

            bool result = dateRange.Contains(dateTime);

            Assert.IsFalse(result);
        }
예제 #12
0
        public void IsShouldCreateMomentWhenProvidedSingleValue()
        {
            // act
            var moment    = new DateTime(2017, 1, 1, 1, 1, 1);
            var dateRange = new DateRange(moment);

            // assert
            dateRange.Contains(moment.AddMilliseconds(1))
            .Should()
            .BeFalse();

            dateRange.Contains(moment.AddMilliseconds(-1))
            .Should()
            .BeFalse();

            dateRange.Contains(moment)
            .Should()
            .BeTrue();
        }
예제 #13
0
        public void DateRange_Test()
        {
            var minDate = DateTime.Parse("2019-01-01");
            var maxDate = DateTime.Parse("2019-12-31");
            var inDate  = DateTime.Parse("2019-05-30");
            var outDate = DateTime.Parse("2018-03-05");

            DateRange range = new DateRange(minDate, maxDate);

            Assert.Equal(minDate, range.MinValue);
            Assert.Equal(maxDate, range.MaxValue);
            Assert.True(range.Contains(inDate));
            Assert.False(range.Contains(outDate));
            Assert.Equal("2019-01-01 00:00:00-2019-12-31 00:00:00", range.ToString("yyyy-MM-dd HH:mm:ss"));

            var range2 = new DateRange();

            Assert.Equal("", range2.ToString());
        }
예제 #14
0
파일: Run.cs 프로젝트: Morebis-GIT/CI
        private static void ValidateProcessRange(
            Run run,
            DateRange dateRange,
            string processName)
        {
            if (dateRange is null)
            {
                throw new ArgumentException($"{processName} process range should not be empty");
            }

            dateRange.Start = UpdateToUTCTime(dateRange.Start);
            dateRange.End   = UpdateToUTCTime(dateRange.End);

            if (dateRange.Start == default || dateRange.End == default)
            {
                throw new ArgumentException($"{processName} process range should not have empty start and end dates");
            }

            if (dateRange.End < dateRange.Start)
            {
                throw new ArgumentException($"{processName} process range start date should be less than or equal to end date");
            }

            if (!IsDateRangeWithInRunPeriod())
            {
                throw new AggregateException($"{processName} range exceed Run Period");
            }

            //------------------------------------------------------------------
            // Local functions

            bool IsDateRangeWithInRunPeriod()
            {
                DateRange result = CreateDateRange(run.StartDate, run.EndDate);

                return(result.Contains(dateRange.Start) && result.Contains(dateRange.End));

                //--------------------------------------------------------------
                // Local functions
                DateRange CreateDateRange(DateTime startDate, DateTime endDate) =>
                new DateRange(startDate.Date, endDate.Date);
            }
        }
예제 #15
0
        public void ItShouldCreateRangeStartedFromBeginningOfDay()
        {
            // act
            var dateRange = new DateRange(1.January(2017), 1.January(2017));

            // assert
            dateRange.Contains(new DateTime(2017, 1, 1, 0, 0, 0))
            .Should()
            .BeTrue();
        }
예제 #16
0
        public void Contains()
        {
            var x = new DateRange(new DateTime(1980, 1, 1), new DateTime(1990, 1, 1));

            Aver.IsTrue(x.Contains(new DateTime(1980, 1, 1)));
            Aver.IsTrue(x.Contains(new DateTime(1990, 1, 1)));

            Aver.IsTrue(x.Contains(new DateTime(1980, 1, 2)));
            Aver.IsTrue(x.Contains(new DateTime(1989, 12, 31)));

            Aver.IsFalse(x.Contains(new DateTime(1979, 12, 31)));
            Aver.IsFalse(x.Contains(new DateTime(1990, 1, 2)));

            Aver.IsFalse(x.Contains(new DateTime(1908, 12, 31)));
            Aver.IsFalse(x.Contains(new DateTime(2003, 1, 2)));

            Aver.IsTrue(x.Contains(new DateTime(1985, 03, 27)));
            Aver.IsTrue(x.Contains(new DateTime(1989, 08, 15)));
        }
예제 #17
0
        public void ItShouldCreateRangeEndedOnLastMSofProvidedDay()
        {
            // act
            var dateRange = new DateRange(1.January(2017), 1.January(2017));

            // assert
            var dateTime = new DateTime(2017, 1, 2).AddMilliseconds(-1);

            dateRange.Contains(dateTime)
            .Should()
            .BeTrue();
        }
예제 #18
0
        private void ADLoginControl1_StateChanged(object o, EventArgs e)
        {
            if (Session[State.AuthUser] == null)
            {
                return;
            }

            String redirectedURL = (String)Session["RedURL"];

            if (!String.IsNullOrEmpty(redirectedURL))
            {
                Session["RedURL"] = null;
                Response.Redirect(redirectedURL);
            }
            ADUser user = (ADUser)Session[State.AuthUser];

            if (user.IsTeacher && (DateTime.Today.DayOfWeek != DayOfWeek.Saturday && DateTime.Today.DayOfWeek != DayOfWeek.Sunday))
            {
                DateRange classDay = new DateRange(DateTime.Today.AddHours(8).AddMinutes(30), DateTime.Today.AddHours(16));
                if (DateTime.Today.DayOfWeek == DayOfWeek.Thursday)
                {
                    classDay = classDay.MoveByHours(1);
                }
                if (Session["RedURL"] != null)
                {
                    Response.Redirect((String)Session["RedURL"]);
                }
                else if (user.IsTeacher)
                {
                    using (WebhostEntities db = new WebhostEntities())
                    {
                        Faculty faculty = db.Faculties.Where(f => f.ID == user.ID).Single();
                        if (faculty.Preferences.Where(p => p.Name.Equals("HomePage")).Count() > 0)
                        {
                            Response.Redirect(faculty.Preferences.Where(p => p.Name.Equals("HomePage")).Single().Value);
                        }
                        else if (classDay.Contains(DateTime.Now))
                        {
                            Response.Redirect("~/TakeAttendance.aspx");
                        }
                        else
                        {
                            Response.Redirect("~/Home.aspx");
                        }
                    }
                }
            }
            else
            {
                Response.Redirect("~/Home.aspx");
            }
        }
예제 #19
0
        public void TestContains()
        {
            DateRange d1, dIncludedInD1, dNotIncludedInD1, d2NotIncludedInD1;

            d1 = new DateRange(august_1_2010, october_1_2010);
            Assert.IsTrue(d1.Contains(d1));
            dIncludedInD1 = new DateRange(august_1_2010, august_1_2010.AddDays(positiveDuration));
            Assert.IsTrue(d1.Contains(dIncludedInD1));
            dNotIncludedInD1 = new DateRange(october_1_2010, october_1_2010.AddDays(positiveDuration));
            Assert.IsFalse(d1.Contains(dNotIncludedInD1));
            d2NotIncludedInD1 = new DateRange(august_1_2010.AddDays(negativeDuration), august_1_2010);
            Assert.IsFalse(d1.Contains(d2NotIncludedInD1));

            DateRange containsCheckEnd = new DateRange(october_1_2010.AddDays(negativeDuration), october_1_2010);

            Assert.IsTrue(d1.Contains(containsCheckEnd));

            Assert.IsTrue(d1.Contains(august_1_2010));
            Assert.IsTrue(d1.Contains(october_1_2010));
            Assert.IsFalse(d1.Contains(august_1_2010.AddDays(negativeDuration)));
            Assert.IsFalse(d1.Contains(october_1_2010.AddDays(positiveDuration)));
        }
예제 #20
0
        public override Tickets Tickets(DateRange dateRange)
        {
            Config config = Config.FromFile("Jira.json");

            using (var client = new WebClient {
                Credentials = config.Credential()
            })
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                string credentials = config.CredentialBase64();
                client.Headers[HttpRequestHeader.Authorization] = $"Basic {credentials}";
                string feedUrl = config.FeedUrl(dateRange);
#if DEBUG
                Console.WriteLine(dateRange.ToString());
                Console.WriteLine(feedUrl);
                Console.WriteLine(config.ToString());
#endif
                string response = client.DownloadString(feedUrl);
#if DEBUG
                Console.WriteLine(response);
#endif
                XDocument  xDocument = XDocument.Parse(response);
                XElement   feed      = ClearNamespaces(xDocument.Root);
                XElement[] entries   = feed.Descendants("entry").ToArray();
                IEnumerable <Tuple <DateTime, string> > tickets = from entry in entries
                                                                  let updated = DateTime.Parse(entry.Element("updated")?.Value)
                                                                                let target                         = entry.Element("target") ?? entry.Element("object")
                                                                                                         let title = target?.Element("title")
                                                                                                                     let summary                       = target?.Element("summary")
                                                                                                                                              let type = target?.Element("object-type")
                                                                                                                                                         where type != null && type.Value.Contains("issue")
                                                                                                                                                         select new Tuple <DateTime, string>(updated, title?.Value + " " + summary?.Value);
                IDictionary <DateTime, string> result = tickets.GroupBy(t => t.Item1.Date, t => t.Item2)
                                                        .OrderByDescending(t => t.Key)
                                                        .Where(t => dateRange.Contains(t.Key))
                                                        .ToDictionary(g => g.Key, g => string.Join(Environment.NewLine, g.Distinct().ToArray()));
                var fr = new Tickets();
                foreach (KeyValuePair <DateTime, string> record in result)
                {
                    fr.Add(record.Key, record.Value);
                }
                return(fr);
            }
        }
        public List <Weather> GetWeather(DateRange dateRange, Location location)
        {
            var json = GetWeatherFromService(location);

            var weatherCodeMapping = Assembly.GetExecutingAssembly()
                                     .GetResource("WeatherAggregator.Sources.WorldWeatherOnline.WeatherCodes.xml");
            var xMapping = XElement.Parse(weatherCodeMapping);

            if (json == null || json.data == null || json.data.weather == null)
            {
                return(new List <Weather>());
            }

            var result = json.data.weather.Where(w => dateRange.Contains(w.date)).Select(w => new Weather
            {
                Date          = w.date,
                Temperature   = (w.tempMinC + w.tempMaxC) / 2,
                Precipitation = GetPrecipitationByCode(w.weatherCode, xMapping),
                Cloudness     = GetCloudnessByCode(w.weatherCode, xMapping)
            }).ToList();

            return(result);
        }
예제 #22
0
 public void AddPlugin(IItem item, DateRange dateRange)
 {
     #region Precondizioni
     if (item == null)
     {
         throw new ArgumentNullException("item null");
     }
     if (dateRange == null)
     {
         throw new ArgumentNullException("dateRange null");
     }
     if (!_rangeData.Contains(dateRange))
     {
         throw new Exception("date range not valid");
     }
     #endregion
     if (!_pluginsAssociation.ContainsKey(item))
     {
         _pluginsAssociation.Add(item, new List <DateRange>());
     }
     (_pluginsAssociation[item] as List <DateRange>).Add(dateRange);
     OnPrenotatitionChangedHandler(this, new ItemPrenotationEventArgs(this));
 }
		public string[] RetrieveAuthors(DateRange dateRange)
		{
			return Revisions.Where(x => dateRange.Contains(x.Time)).Select(x => x.Author).ToArray();
		}
예제 #24
0
        public void LoadRow()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int     yr      = DateRange.GetCurrentAcademicYear();
                Student student = db.Students.Where(s => s.ID == StudentId).Single();
                List <AttendanceMarking> atts = student.AttendanceMarkings.Where(mk => mk.AttendanceDate.Equals(Date) && mk.SectionIndex == StudyHallId).ToList();
                NameLabel.Text           = String.Format("{0} {1} [{2}]", student.FirstName, student.LastName, student.GraduationYear);
                AttendanceDDL.DataSource = (from lbl in db.GradeTableEntries
                                            where lbl.GradeTable.AcademicYearID == yr && lbl.GradeTable.Name.Equals("Attendance")
                                            select lbl).ToList();
                AttendanceDDL.DataTextField  = "Name";
                AttendanceDDL.DataValueField = "id";
                AttendanceDDL.DataBind();

                if (atts.Count() > 0)
                {
                    AttendanceDDL.ClearSelection();
                    AttendanceDDL.SelectedValue = Convert.ToString(atts[0].MarkingIndex);
                    MarkBtn.Text = "Checked In--Click to Update Status";
                }

                if (student.AcademicLevel > 1)
                {
                    LibraryPanel.Visible = true;

                    if (student.AcademicLevel == 3)
                    {
                        SignOutBtn.Visible    = false;
                        SignedOutInfo.Visible = false;
                        LibraryLabel.Text     = "Independent";
                        return;
                    }

                    DateTime           Sunday   = DateTime.Today.DayOfWeek.Equals(DayOfWeek.Sunday) ? DateTime.Today : DateRange.ThisFriday.AddDays(-5);
                    DateRange          thisWeek = new DateRange(Sunday, Sunday.AddDays(6));
                    List <LibraryPass> passes   = student.LibraryPasses.Where(p => thisWeek.Contains(p.LibraryDay)).ToList();
                    List <DateTime>    dates    = new List <DateTime>();
                    foreach (LibraryPass pass in passes)
                    {
                        if (!dates.Contains(pass.LibraryDay))
                        {
                            dates.Add(pass.LibraryDay);
                        }
                    }

                    if (dates.Count > 1)
                    {
                        LibraryLabel.Text  = "No Library Passes Remaining!";
                        SignOutBtn.Enabled = false;
                    }
                    else
                    {
                        LibraryLabel.Text  = String.Format("{0} Libary Passes Remaining.", 2 - dates.Count);
                        SignOutBtn.Enabled = true;
                    }

                    if (passes.Where(p => p.LibraryDay.Equals(DateTime.Today)).Count() > 0)
                    {
                        LibraryPass pass = passes.Where(p => p.LibraryDay.Equals(DateTime.Today)).FirstOrDefault();
                        if (pass.StudyHallSignatureId.HasValue)
                        {
                            SignOutBtn.Visible    = false;
                            CancelPassBtn.Visible = true;
                            SignedOutInfo.Visible = true;
                            SignedOutInfo.Text    = String.Format("Left Study Hall {0}{3}Signed {1} {2}{3}", pass.StudyHallCheckOutSignature.TimeStamp.ToShortTimeString(), pass.StudyHallCheckOutSignature.Faculty.FirstName, pass.StudyHallCheckOutSignature.Faculty.LastName, Environment.NewLine);
                            if (pass.LibrarySignatureId.HasValue)
                            {
                                SignedOutInfo.Text += String.Format("Left Study Hall {0}{3}Signed {1} {2}{3}", pass.LibraryCheckInSignature.TimeStamp.ToShortTimeString(), pass.LibraryCheckInSignature.Faculty.FirstName, pass.LibraryCheckInSignature.Faculty.LastName, Environment.NewLine);
                            }
                        }
                    }
                    else
                    {
                        SignOutBtn.Visible    = true;
                        CancelPassBtn.Visible = false;
                    }
                }
                else
                {
                    LibraryPanel.Visible = false;
                }
            }
        }
 public static bool Contains(this DateRange x, DateRange y)
 {
     return(x.Contains(y.StartDateTime) && x.Contains(y.EndDateTime));
 }
 public string[] RetrieveAuthors(DateRange dateRange)
 {
     return(Revisions.Where(x => dateRange.Contains(x.Time)).Select(x => x.Author).ToArray());
 }
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            LogInformation("Attempting To Submit an excused absence.");
            int studentId;

            try
            {
                studentId = Convert.ToInt32(StudentNameCBX.SelectedValue);
            }
            catch
            {
                ShowError("You must select a student to excuse.");
                return;
            }

            DateTime date = DateTime.Today;

            if (!TodayCB.Checked)
            {
                try
                {
                    date = DateRange.GetDateTimeFromString(DateInput.Text);
                }
                catch
                {
                    ShowError("Please select a date using the calendar.");
                    return;
                }
            }

            if (NotesInput.Text.Equals(""))
            {
                ShowError("You must enter a reason for the excused absence.");
                return;
            }

            List <int> selectedBlocks = new List <int>();

            foreach (ListItem item in BlocksCBL.Items)
            {
                if (item.Selected)
                {
                    selectedBlocks.Add(Convert.ToInt32(item.Value));
                }
            }

            using (WebhostEntities db = new WebhostEntities())
            {
                List <int> sectionIds = new List <int>();
                Term       theTerm    = null;

                foreach (Term term in db.Terms)
                {
                    DateRange termrange = new DateRange(term.StartDate, term.EndDate);
                    if (termrange.Contains(date))
                    {
                        theTerm = term;
                        break;
                    }
                }

                if (theTerm == null)
                {
                    ShowError("The selected Date is not in any Term.");
                    return;
                }

                foreach (int blkid in selectedBlocks)
                {
                    Block block = db.Blocks.Where(b => b.id == blkid).Single();
                    foreach (Section section in block.Sections.Where(sec => sec.Terms.Contains(theTerm)).ToList())
                    {
                        if (section.Students.Where(stu => stu.ID == studentId).Count() > 0)
                        {
                            sectionIds.Add(section.id);
                        }
                    }
                }

                if (MultiDayCB.Checked)
                {
                    DateTime end = new DateTime();
                    try
                    {
                        end = DateRange.GetDateTimeFromString(EndDateInput.Text);
                    }
                    catch
                    {
                        ShowError("Please select the End Date from the calendar.");
                        return;
                    }

                    String report = AttendanceControl.ExcuseStudent(studentId, sectionIds, NotesInput.Text, ((BasePage)Page).user, new DateRange(date, end));
                    State.log.WriteLine(report);
                }
                else
                {
                    String report = AttendanceControl.ExcuseStudent(studentId, sectionIds, NotesInput.Text, ((BasePage)Page).user, date);
                    State.log.WriteLine(report);
                }

                LogInformation("Excused attendance submitted for student id {0}.  See Webhost MySQL Connection log for details.", studentId);
            }
        }