Esempio n. 1
0
        public void MapFormFieldsToEntity()
        {
            // Save match date/time to entity
            if (MatchDate.HasValue && MatchTimeFrom.HasValue && MatchTimeTo.HasValue)
            {
                var period = new DateTimePeriod(MatchDate?.Add(MatchTimeFrom.Value), MatchDate?.Add(MatchTimeTo.Value));
                Match.SetRealStart(TimeZoneConverter.ToUtc(period.Start), period.Duration());
            }
            else
            {
                Match.SetRealStart(null, TimeSpan.Zero);
            }

            // Add sets to entity
            Match.Sets.Clear(true);
            for (var i = 0; i < Sets.Count; i++)
            {
                // sets where home and guest ball points are NULL, will be ignored
                if (Sets[i].Home.HasValue || Sets[i].Guest.HasValue)
                {
                    // home or guest NULL values are invalidated with -1
                    Match.Sets.Add(new SetEntity {
                        MatchId = Match.Id, SequenceNo = i + 1, HomeBallPoints = Sets[i].Home ?? -1, GuestBallPoints = Sets[i].Guest ?? -1
                    });
                }
            }

            // point calculation must run before validation because of tie-break handling
            Match.Sets.CalculateSetPoints(Round.SetRule, Round.MatchRule);
            Match.Remarks = Remarks;
            Match.ChangeSerial++;
            Match.IsComplete = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor defining a time period
        /// </summary>
        /// <param name="actualDate"></param>
        /// <param name="period"></param>
        public DateTimeRange(DateTime actualDate, DateTimePeriod period)
        {
            switch (period)
            {
            case DateTimePeriod.Day:
                BeginDate = actualDate.BeginDay();
                EndDate   = actualDate.EndDay();
                break;

            case DateTimePeriod.Month:
                BeginDate = actualDate.BeginMonth();
                EndDate   = actualDate.EndMonth();
                break;

            case DateTimePeriod.Quarter:
                BeginDate = actualDate.BeginQuarter();
                EndDate   = actualDate.EndQuarter();
                break;

            case DateTimePeriod.HalfYear:
                BeginDate = actualDate.BeginHalfYear();
                EndDate   = actualDate.EndHalfYear();
                break;

            case DateTimePeriod.Year:
                BeginDate = actualDate.BeginYear();
                EndDate   = actualDate.EndYear();
                break;
            }
        }
        public void Overlaps(DateTime?dt1, DateTime?dt2, bool expected)
        {
            var dtp1 = new DateTimePeriod(new DateTime(2020, 06, 01), new DateTime(2020, 06, 04));
            var dtp2 = new DateTimePeriod(dt1, dt2);

            Assert.AreEqual(expected, dtp1.Overlaps(dtp2));
        }
Esempio n. 4
0
        public void FromTest()
        {
            var d = new DateTimePeriod();

            d.OnChanged += DoOnChanged;
            d.From       = DateTime.Now;
        }
Esempio n. 5
0
            public static DateTimePeriod Union(DateTimePeriod p1, DateTimePeriod p2)
            {
                DateTime t1 = p1.Start <p2.Start?p1.Start : p2.Start,
                                        t2 = p1.End> p2.End ? p1.End : p2.End;

                return(new DateTimePeriod(t1, t2));
            }
Esempio n. 6
0
            public bool IntersectsWith(DateTimePeriod period)
            {
                Rect r1 = new Rect(Start.Ticks, 0, End.Ticks, 10),
                     r2 = new Rect(period.Start.Ticks, 0, period.End.Ticks, 10);

                return(r1.IntersectsWith(r2));
            }
        private RangeFilterDashboardItem CreateRangeFilter(IDashboardDataSource dataSource)
        {
            RangeFilterDashboardItem rangeFilter = new RangeFilterDashboardItem();

            rangeFilter.DataSource = dataSource;
            SimpleSeries salesAmountSeries = new SimpleSeries(SimpleSeriesType.Area);

            rangeFilter.Series.Add(salesAmountSeries);
            salesAmountSeries.Value = new Measure("Extended Price");
            rangeFilter.Argument    = new Dimension("OrderDate");
            rangeFilter.Argument.DateTimeGroupInterval = DateTimeGroupInterval.MonthYear;
            rangeFilter.FilterString = "[OrderDate] > #2018-01-01#";
            rangeFilter.DateTimePeriods.AddRange(
                DateTimePeriod.CreateLastYear(),
                DateTimePeriod.CreateNextMonths("Next 3 Months", 3),
                new DateTimePeriod
            {
                Name  = "Year To Date",
                Start = new FlowDateTimePeriodLimit(DateTimeInterval.Year, 0),
                End   = new FlowDateTimePeriodLimit(DateTimeInterval.Day, 1)
            },
                new DateTimePeriod
            {
                Name  = "Jul-18-2018 - Jan-18-2019",
                Start = new FixedDateTimePeriodLimit(new DateTime(2018, 7, 18)),
                End   = new FixedDateTimePeriodLimit(new DateTime(2019, 1, 18))
            }
                );
            rangeFilter.DefaultDateTimePeriodName = "Year To Date";
            // The caption is initially hidden. Uncomment the line below to show the caption.
            //rangeFilter.ShowCaption = true;
            return(rangeFilter);
        }
        private void PushToSingleton()
        {
            BookingSingleton singleton = BookingSingleton.Instance;
            string           myDate    = SelectedDate.ToString("dd/MM/yyyy");
            DateTimePeriod   date      = DateTimePeriodConverter.ToDate(myDate);

            singleton.SelectedDate = date;
        }
Esempio n. 9
0
        public PostControl()
        {
            Period = new DateTimePeriod(DateTime.Now.Date.AddDays(-14), DateTime.Now.Date);

            var txt = new FormattedText("00", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, face, fontSize, Foreground);

            sizeText = new Size(txt.Width, txt.Height);
        }
        public void PeriodSpliting()
        {
            var addedDays = 10;
            var p         = new DateTimePeriod(DateTime.Now, DateTime.Now.AddDays(addedDays));
            var result    = p.SplitToPeriodsByDays();

            Assert.IsTrue(result != null && result.Count() == addedDays + 1);
        }
Esempio n. 11
0
        public void op_Contains_DateTime(bool expected,
                                         string value)
        {
            var period = new DateTimePeriod(XmlConvert.ToDateTime("2012-11-01T00:00:00Z", XmlDateTimeSerializationMode.Utc),
                                            XmlConvert.ToDateTime("2012-11-30T23:59:59Z", XmlDateTimeSerializationMode.Utc));
            var actual = period.Contains(XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.Utc));

            Assert.Equal(expected, actual);
        }
        public void DateTimePeriodSerializationTest()
        {
            DateTimePeriod per    = new DateTimePeriod(DateTime.Now, DateTime.Now.AddDays(1));
            string         result = JsonConvert.SerializeObject(per);

            var per2 = JsonConvert.DeserializeObject <DateTimePeriod>(result);

            Assert.IsTrue(per.Start == per2.Start && per.End == per2.End);
        }
        public void CreationAndAssigningWithTimeSpanAndSwap(DateTime?date1, TimeSpan?timeSpan)
        {
            var dtp = new DateTimePeriod(date1, timeSpan);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(date1, dtp.End);
                Assert.AreEqual(timeSpan.HasValue ? date1?.Add(timeSpan.Value) : null, dtp.Start);
            });
        }
        public void CreationAndAssigningWithTimeSpan(DateTime date1, TimeSpan timeSpan)
        {
            var dtp = new DateTimePeriod(date1, timeSpan);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(date1, dtp.Start);
                Assert.AreEqual(date1.Add(timeSpan), dtp.End);
            });
        }
        public void CreationAndAssigningDefaultCtor()
        {
            var dtp = new DateTimePeriod();

            Assert.Multiple(() =>
            {
                Assert.AreEqual(dtp.Start, dtp.End);
                Assert.IsNull(dtp.Start);
            });
        }
        public void CreationAndAssigning(DateTime date1, DateTime date2, bool expected)
        {
            var dtp = new DateTimePeriod(date1, date2);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(date1, dtp.Start);
                Assert.AreEqual(date2, dtp.End);
            });
        }
        public void OnlyDates_Ok()
        {
            var startDate = new DateTime(2019, 06, 04);
            var endDate   = new DateTime(2019, 06, 05);

            var period = new DateTimePeriod(startDate, endDate);

            Assert.Equal(startDate, period.Start);
            Assert.Equal(endDate, period.End);
        }
        public void OnlyDatesWithDayRange_Ok()
        {
            var startDate = new DateTime(2019, 06, 04);
            var endDate   = new DateTime(2019, 06, 05);

            var period = new DateTimePeriod(startDate, endDate, dayRange: true);

            Assert.Equal(startDate, period.Start);
            Assert.Equal(endDate.Date.AddDays(1).Subtract(TimeSpan.FromMilliseconds(1)), period.End);
        }
        public void MaxDateTimePrecisionIsOneSecond()
        {
            var date1 = new DateTime(2020, 06, 01, 18, 18, 18).AddTicks(20);
            var date2 = new DateTime(2020, 06, 01, 18, 18, 18).AddTicks(30);
            var dtp   = new DateTimePeriod(date1, date2);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(dtp.Start, dtp.End);
                Assert.AreNotEqual(date1, dtp.Start);
            });
        }
Esempio n. 20
0
        public async Task <Unit> Handle(BorrowBookCommand command, CancellationToken cancellationToken)
        {
            var storage = await _storageRepository.GetAsync(_storageConfig.DevelopStorageId);

            var dateTimePeriod = DateTimePeriod.Create(command.BorrowingStartDate, command.BorrowingEndDate);

            storage.BorrowBook(command.BookId, _tokenAuthInfo.UserId, dateTimePeriod);

            await _storageRepository.SaveChangesAsync();

            return(Unit.Value);
        }
        public void DatesWithSeparateTimeWithDayRange_Ok()
        {
            var startDate = new DateTime(2019, 06, 04);
            var startTime = new TimeSpan(11, 00, 00);
            var endDate   = new DateTime(2019, 06, 05);
            var endTime   = new TimeSpan(12, 00, 00);

            var period = new DateTimePeriod(startDate, endDate, startTime, endTime, true);

            Assert.Equal(startDate.Add(startTime), period.Start);
            Assert.Equal(endDate.Date.AddDays(1).Subtract(TimeSpan.FromMilliseconds(1)), period.End);
        }
        public void DatesWithSeparateTime_TimeOfDateErased()
        {
            var startDate = new DateTime(2019, 06, 04, 10, 0, 0);
            var startTime = new TimeSpan(11, 00, 00);
            var endDate   = new DateTime(2019, 06, 05, 15, 0, 0);
            var endTime   = new TimeSpan(12, 00, 00);

            var period = new DateTimePeriod(startDate, endDate, startTime, endTime);

            Assert.Equal(startDate.Date.Add(startTime), period.Start);
            Assert.Equal(endDate.Date.Add(endTime), period.End);
        }
Esempio n. 23
0
        /// <summary>
        /// Returns end <see cref="System.DateTime" /> of period.
        /// </summary>
        /// <param name="target">Target date.</param>
        /// <param name="period">Period type.</param>
        /// <param name="cultureInfo">Specific culture to use. If null current culture is used.</param>
        /// <returns>End of period date.</returns>
        public static DateTime GetEndOfPeriod(DateTime target, DateTimePeriod period, CultureInfo cultureInfo = null)
        {
            var result = target.Truncate(period);

            switch (period)
            {
            case DateTimePeriod.Millisecond:
                result = result.AddMilliseconds(1);
                break;

            case DateTimePeriod.Second:
                result = result.AddSeconds(1);
                break;

            case DateTimePeriod.Minute:
                result = result.AddMinutes(1);
                break;

            case DateTimePeriod.Hour:
                result = result.AddHours(1);
                break;

            case DateTimePeriod.Day:
                result = result.AddDays(1);
                break;

            case DateTimePeriod.Week:
                result = result.AddDays(7);
                break;

            case DateTimePeriod.Month:
                result = result.AddMonths(1);
                break;

            case DateTimePeriod.Quarter:
                result = result.AddMonths(4);
                break;

            case DateTimePeriod.Year:
                result = result.AddYears(1);
                break;

            case DateTimePeriod.Decade:
                result = result.AddYears(10);
                break;

            case DateTimePeriod.None:
            default:
                return(target);
            }
            return(result.AddMilliseconds(-1));
        }
        public void CreationAndAssigningWithSwap()
        {
            // swap start and end so that always start <= end
            var date1 = new DateTime(2020, 06, 02);
            var date2 = new DateTime(2020, 06, 01);
            var dtp   = new DateTimePeriod(date1, date2);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(date1, dtp.End);
                Assert.AreEqual(date2, dtp.Start);
            });
        }
        public void StartGreaterEnd_Throws()
        {
            var startDate = new DateTime(2019, 06, 04);
            var endDate   = new DateTime(2019, 06, 05);

            try
            {
                var period = new DateTimePeriod(endDate, startDate);
                Assert.True(false);
            }
            catch
            {
                // ignored
            }
        }
Esempio n. 26
0
        private DateTimePeriod ExtractPeriod()
        {
            var period = new DateTimePeriod();

            if (_abumViewModel.From.HasValue)
            {
                period.From = _abumViewModel.From.Value;
            }
            if (_abumViewModel.To.HasValue)
            {
                period.To = _abumViewModel.To.Value;
            }

            return(period);
        }
Esempio n. 27
0
        /// <summary>
        /// Shortcut to set date part. Method throws <see cref="System.ArgumentException" /> for
        /// week and quarter periods.
        /// </summary>
        /// <param name="target">Target date.</param>
        /// <param name="period">Period to replace.</param>
        /// <param name="value">Value to replace by.</param>
        /// <returns>The date with new value.</returns>
        public static DateTime SetPart(DateTime target, DateTimePeriod period, int value)
        {
            switch (period)
            {
            case DateTimePeriod.Millisecond:
                return(new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, target.Second,
                                    value, target.Kind));

            case DateTimePeriod.Second:
                return(new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, value,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Minute:
                return(new DateTime(target.Year, target.Month, target.Day, target.Hour, value, target.Second,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Hour:
                return(new DateTime(target.Year, target.Month, target.Day, value, target.Minute, target.Second,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Day:
                return(new DateTime(target.Year, target.Month, value, target.Hour, target.Minute, target.Second,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Week:
                throw new ArgumentException(
                          String.Format(Properties.Strings.ArgumentCannotBeThePeriod, period), nameof(period));

            case DateTimePeriod.Month:
                return(new DateTime(target.Year, value, target.Day, target.Hour, target.Minute, target.Second,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Quarter:
                throw new ArgumentException(string.Format(Properties.Strings.ArgumentCannotBeThePeriod, period), nameof(period));

            case DateTimePeriod.Year:
                return(new DateTime(value, target.Month, target.Day, target.Hour, target.Minute, target.Second,
                                    target.Millisecond, target.Kind));

            case DateTimePeriod.Decade:
                throw new ArgumentException(
                          String.Format(Properties.Strings.ArgumentCannotBeThePeriod, period), nameof(period));

            case DateTimePeriod.None:
            default:
                return(target);
            }
        }
Esempio n. 28
0
        public void IterateByStep()
        {
            var period = new DateTimePeriod()
            {
                Start = new DateTime(2019, 11, 26),
                End   = new DateTime(2019, 12, 01),
            };

            var days = period.ToDateTimeList(Step.Day);

            days.Should().HaveCount(5);
            foreach (var day in days)
            {
                _output.WriteLine($"{day}");
            }
        }
        public void op_Months_int()
        {
            var expected = new DateTimePeriod();

            var mock = new Mock<ICalculateDateTimePeriod<Date>>();
            mock
                .Setup(x => x.Months(1))
                .Returns(expected)
                .Verifiable();

            var actual = mock.Object.Months(1);

            Assert.Equal(expected, actual);

            mock.VerifyAll();
        }
Esempio n. 30
0
        public IEnumerable <ExcludeMatchDateEntity> Import(string?specialHolidaysXmlFile,
                                                           DateTimePeriod dateLimits, Predicate <Axuno.Tools.GermanHoliday> holidayFilter)
        {
            if (!(dateLimits.Start.HasValue && dateLimits.End.HasValue))
            {
                throw new ArgumentException("Lower and upper date limits must be set.", nameof(dateLimits));
            }

            _logger.LogTrace("Starting import of German holidays for period {0} to {1}", dateLimits.Start, dateLimits.End);

            var currentYear = ((DateTime)dateLimits.Start).Year;

            // stores all holidays within the dateLimits
            var holidays = new List <Axuno.Tools.GermanHoliday>();

            while (currentYear <= ((DateTime)dateLimits.End).Year)
            {
                _logger.LogTrace("Processing year '{0}'", currentYear);
                var currentYearHolidays = new Axuno.Tools.GermanHolidays(currentYear);
                _logger.LogTrace("Generated {0} holidays.", currentYearHolidays.Count);

                // The holidays file must be imported **for each year**
                if (!string.IsNullOrEmpty(specialHolidaysXmlFile))
                {
                    currentYearHolidays.Load(specialHolidaysXmlFile);
                    _logger.LogTrace("Holidays from file '{0}' loaded. Now counts {1} for year {2}", specialHolidaysXmlFile, currentYearHolidays.Count, currentYear);
                }

                holidays.AddRange(currentYearHolidays.GetFiltered(holidayFilter));

                // Filter is now an argument to Import method:
                // filter by federal or Bavarian holidays, which are public, custom or school holidays

                /*holidays.AddRange(
                 *  currentYearHolidays.GetFiltered(
                 *      h =>
                 *          (h.PublicHolidayStateIds.Count == 0 ||
                 *           h.PublicHolidayStateIds.Contains(Axuno.Tools.GermanFederalStates.Id.Bayern)) &&
                 *          (h.Type == Axuno.Tools.GermanHolidays.Type.Public ||
                 *           h.Type == Axuno.Tools.GermanHolidays.Type.Custom ||
                 *           h.Type == Axuno.Tools.GermanHolidays.Type.School)));
                 */
                currentYear++;
            }

            return(Map(holidays, dateLimits));
        }
Esempio n. 31
0
        public AlbumEntity CreateAlbumEntity()
        {
            int            id          = _abumViewModel.Id;
            string         title       = ExtractTitle();
            string         description = ExtractDescription();
            PlaceEntity    place       = ExtractPlace();
            DateTimePeriod period      = ExtractPeriod();

            return(new AlbumEntity
            {
                Id = id,
                Title = title,
                Description = description,
                Place = place,
                Period = period
            });
        }
Esempio n. 32
0
        /// <summary>
        /// Imports excluded match dates from an Excel workbook. The first worksheet of the workbook will be used.
        /// 3 expected columns: <see cref="DateTime"/> DateFrom, <see cref="DateTime"/> DateTo, <see cref="string"/> Reason.
        /// </summary>
        /// <remarks>
        /// Excel date values are considered as local time and will be converted to UTC.
        /// A maximum of 1,000 rows will be imported.
        /// </remarks>
        /// <param name="xlPathAndFileName">The path to the Excel file.</param>
        /// <param name="dateLimits">The limits for dates, which will be imported.</param>
        /// <returns>
        /// Returns an <see cref="IEnumerable{T}" />of <see cref="ExcludeMatchDateEntity"/>.
        /// <see cref="ExcludeMatchDateEntity.TournamentId"/>, <see cref="ExcludeMatchDateEntity.RoundId"/> and <see cref="ExcludeMatchDateEntity.TeamId"/> will not be set.
        /// </returns>
        public IEnumerable <ExcludeMatchDateEntity> Import(string xlPathAndFileName, DateTimePeriod dateLimits)
        {
            var xlFile = new FileInfo(xlPathAndFileName);

            _logger.LogTrace("Opening Excel file '{0}'", xlPathAndFileName);
            using var package = new ExcelPackage(xlFile);

            var worksheet = package.Workbook.Worksheets.First();

            _logger.LogTrace("Using the first worksheet, '{0}'", worksheet.Name);
            _logger.LogTrace("Date limits are {0} - {1}", dateLimits.Start, dateLimits.End);
            var row = 0;

            while (true)
            {
                row++;
                if (row == 1 && !(worksheet.Cells[row, 1].Value is DateTime))
                {
                    _logger.LogTrace("First cell is not a date, assume existing headline row");
                    continue; // may contain a headline row
                }


                if (!(worksheet.Cells[row, 1].Value is DateTime from && worksheet.Cells[row, 2].Value is DateTime to) ||
                    row > 1000)
                {
                    _logger.LogTrace("Import finished with worksheet row {0}", row - 1);
                    yield break;
                }


                from = _timeZoneConverter.ToUtc(from.Date);
                to   = _timeZoneConverter.ToUtc(to.Date);

                if (!dateLimits.Overlaps(new DateTimePeriod(from, to)))
                {
                    _logger.LogTrace("UTC Dates {0} - {1} are out of limits", from, to);
                    continue;
                }

                var reason = worksheet.Cells[row, 3].Value as string ?? string.Empty;
                yield return(CreateEntity((from, to, reason)));

                _logger.LogTrace("Imported UTC {0} - {1} ({2})", from, to, reason);
            }
        }
        public void op_Since_T()
        {
            var expected = new DateTimePeriod();
            var value = Date.Today.LocalTime;

            var mock = new Mock<ICalculateDateTimePeriod<Date>>();
            mock
                .Setup(x => x.Since(value))
                .Returns(expected)
                .Verifiable();

            var actual = mock.Object.Since(value);

            Assert.Equal(expected, actual);

            mock.VerifyAll();
        }
Esempio n. 34
0
        public void prop_Period_Years_intZero()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = date.ToDateTime(),
                                   Beginning = date.ToDateTime()
                               };
            var actual = date.Period.Years(0);

            Assert.Equal(expected, actual);
        }
Esempio n. 35
0
        public void prop_Ending_set(string beginning,
                                    string ending)
        {
            var obj = new DateTimePeriod(XmlConvert.ToDateTime(beginning, XmlDateTimeSerializationMode.Utc), DateTime.MaxValue);

            Assert.DoesNotThrow(() => obj.Ending = XmlConvert.ToDateTime(ending, XmlDateTimeSerializationMode.Utc));
        }
Esempio n. 36
0
        public void prop_Duration_get()
        {
            var expected = DateTime.MaxValue - DateTime.MinValue;
            var actual = new DateTimePeriod(DateTime.MinValue, DateTime.MaxValue).Duration;

            Assert.Equal(expected, actual);
        }
Esempio n. 37
0
        public void prop_Period_Weeks_int()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = date.AddDays(13).ToDateTime(),
                                   Beginning = date.ToDateTime()
                               };
            var actual = date.Period.Weeks(2);

            Assert.Equal(expected, actual);
        }
Esempio n. 38
0
        public void prop_Calendar_Week_whenSunday()
        {
            var date = new Date(2012, 11, 4);

            var expected = new DateTimePeriod
                               {
                                   Ending = new DateTime(2012, 11, 4),
                                   Beginning = new DateTime(2012, 10, 29)
                               };
            var actual = date.Calendar.Week;

            Assert.Equal(expected, actual);
        }
Esempio n. 39
0
        public void prop_Period_Since_DateSame()
        {
            var date = Date.Today.LocalTime;
            var since = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = since.ToDateTime(),
                                   Beginning = date.ToDateTime()
                               };
            var actual = date.Period.Since(since);

            Assert.Equal(expected, actual);
        }
Esempio n. 40
0
        public void prop_Period_Between_DateSame()
        {
            var date = Date.Today.LocalTime;
            var other = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = other.ToDateTime(),
                                   Beginning = date.ToDateTime()
                               };
            var actual = date.Period.Between(other);

            Assert.Equal(expected, actual);
        }
Esempio n. 41
0
        public void prop_Period_Years_intNegative()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = date.ToDateTime(),
                                   Beginning = date.AddYears(-1).AddDays(1).ToDateTime()
                               };
            var actual = date.Period.Years(-1);

            Assert.Equal(expected, actual);
        }
 public void OnTestInitialize()
 {
     _dateTime1 = new DateTime(2010, 1, 1);
     _dateTime2 = new DateTime(2014, 1, 1);
     _dateTimePeriod = new DateTimePeriod(_dateTime1, _dateTime2);
 }
Esempio n. 43
0
        public void prop_Ending_set_whenArgumentOutOfRangeException(string beginning,
                                                                    string ending)
        {
            var obj = new DateTimePeriod(XmlConvert.ToDateTime(beginning, XmlDateTimeSerializationMode.Utc), DateTime.MaxValue);

            Assert.Throws<ArgumentOutOfRangeException>(() => obj.Ending = XmlConvert.ToDateTime(ending, XmlDateTimeSerializationMode.Utc));
        }
Esempio n. 44
0
        public void prop_Calendar_Year()
        {
            var date = new Date(2012, 11, 10);

            var expected = new DateTimePeriod
                               {
                                   Ending = new DateTime(2012, 12, 31),
                                   Beginning = new DateTime(2012, 1, 1)
                               };
            var actual = date.Calendar.Year;

            Assert.Equal(expected, actual);
        }
Esempio n. 45
0
        public void prop_Period_Until_DateSame()
        {
            var date = Date.Today.LocalTime;
            var until = Date.Today.LocalTime;

            var expected = new DateTimePeriod
                               {
                                   Ending = until.ToDateTime(),
                                   Beginning = date.ToDateTime()
                               };
            var actual = date.Period.Until(until);

            Assert.Equal(expected, actual);
        }