Beispiel #1
0
        private static NundinalLetters CheckNundialLetter(LocalDateTime from, LocalDateTime to, NundinalLetters startPosition)
        {
            var daysFromStart = Math.Abs(to.Minus(new LocalDateTime(from.Year, 1, 1, 0, 0)).Days);
            var daysFromCycle = (((daysFromStart + (int)startPosition)) % 8);

            return((NundinalLetters)daysFromCycle);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="timePeriod"> the time period </param>
 /// <param name="endTime"> the end time of the tick period </param>
 public Tick(Period timePeriod, LocalDateTime endTime)
 {
     CheckTimeArguments(timePeriod, endTime);
     _timePeriod = timePeriod;
     _endTime    = endTime;
     _beginTime  = endTime.Minus(timePeriod);
 }
Beispiel #3
0
        public IEnumerable <Tuple <LocalDate, Duration> > GetDurationForEachDate(ZonedDateTime first, ZonedDateTime last)
        {
            var returnList = new List <Tuple <LocalDate, Duration> >();
            var firstKey   = new LocalDate(first.Year, first.Month, first.Day);
            var lastKey    = new LocalDate(last.Year, last.Month, last.Day);

            var localFirst = first.LocalDateTime;
            var localLast  = last.LocalDateTime;

            LocalDateTime endOfFirst      = new LocalDateTime(first.Year, first.Month, first.Day, 23, 59, 59);
            LocalDateTime beginningOfLast = new LocalDateTime(last.Year, last.Month, last.Day, 0, 0, 0);

            returnList.Add(new Tuple <LocalDate, Duration>(firstKey, endOfFirst.Minus(localFirst).ToDuration()));

            var dateIterator = endOfFirst.PlusSeconds(1);

            HashSet <LocalDate> datesSeen = new HashSet <LocalDate>();

            datesSeen.Add(firstKey);

            while (dateIterator < beginningOfLast)
            {
                var date = new LocalDate(dateIterator.Year, dateIterator.Month, dateIterator.Day);
                datesSeen.Add(date);

                returnList.Add(new Tuple <LocalDate, Duration>(date, Duration.FromDays(1)));
                dateIterator = dateIterator.PlusHours(24);
            }

            returnList.Add(new Tuple <LocalDate, Duration>(lastKey, localLast.Minus(beginningOfLast).ToDuration()));

            return(returnList);
        }
Beispiel #4
0
        /// <summary>
        /// Obtains Weight objects from HealthVault
        /// </summary>
        /// <returns></returns>
        public override async Task Initialize(NavigationParams navParams)
        {
            //Save the connection so that we can reuse it for updates later
            _connection = navParams.Connection;

            HealthRecordInfo recordInfo  = (await _connection.GetPersonInfoAsync()).SelectedRecord;
            IThingClient     thingClient = _connection.CreateThingClient();

            if (QueryTimeframe.SelectedIndex == (int)QueryTimeframeEnum.Default)
            {
                //Uses a simple query which specifies the Thing type as the only filter
                Items = await thingClient.GetThingsAsync <Weight>(recordInfo.Id);
            }
            else if (QueryTimeframe.SelectedIndex == (int)QueryTimeframeEnum.Last30d)
            {
                LocalDateTime localNow = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime;

                //In this mode, the app specifies a ThingQuery which can be used for functions like
                //filtering, or paging through values
                ThingQuery query = new ThingQuery
                {
                    EffectiveDateMin = localNow.Minus(Period.FromDays(30))
                };

                Items = await thingClient.GetThingsAsync <Weight>(recordInfo.Id, query);
            }

            OnPropertyChanged("Items");
            OnPropertyChanged("Latest");

            return;
        }
    public void Past_with_custom_options()
    {
        var starting = new LocalDateTime(2015, 6, 6, 4, 17, 41);

        dataSet.Past(reference: starting, daysToGoBack: 500).Should()
        .BeLessOrEqualTo(starting)
        .And
        .BeGreaterOrEqualTo(starting.Minus(Period.FromDays(500)));
    }
    public void Past()
    {
        var starting = new LocalDateTime(2015, 6, 6, 4, 17, 41);

        dataSet.Past(reference: starting).Should()
        .BeLessOrEqualTo(starting)
        .And
        .BeGreaterOrEqualTo(starting.Minus(Period.FromDays(100)));
    }
        // No tests for non-ISO-day-of-week calendars as we don't have any yet.

        public void Operator_MethodEquivalents()
        {
            LocalDateTime start  = new LocalDateTime(2011, 1, 1, 15, 25, 30, 100, 5000);
            Period        period = Period.FromHours(1) + Period.FromDays(1);

            Assert.AreEqual(start + period, LocalDateTime.Add(start, period));
            Assert.AreEqual(start + period, start.Plus(period));
            Assert.AreEqual(start - period, LocalDateTime.Subtract(start, period));
            Assert.AreEqual(start - period, start.Minus(period));
        }
Beispiel #8
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="timePeriod"> the time period </param>
 /// <param name="endTime"> the end time of the tick period </param>
 /// <param name="openPrice"> the open price of the tick period </param>
 /// <param name="highPrice"> the highest price of the tick period </param>
 /// <param name="lowPrice"> the lowest price of the tick period </param>
 /// <param name="closePrice"> the close price of the tick period </param>
 /// <param name="volume"> the volume of the tick period </param>
 public Tick(Period timePeriod, LocalDateTime endTime, Decimal openPrice, Decimal highPrice, Decimal lowPrice, Decimal closePrice, Decimal volume)
 {
     CheckTimeArguments(timePeriod, endTime);
     _timePeriod = timePeriod;
     _endTime    = endTime;
     _beginTime  = endTime.Minus(timePeriod);
     _openPrice  = openPrice;
     _maxPrice   = highPrice;
     _minPrice   = lowPrice;
     _closePrice = closePrice;
     _volume     = volume;
 }
        public void Subtraction_OffsetDateTime()
        {
            // Test all three approaches... not bothering to check a different calendar,
            // but we'll use two different offsets.
            OffsetDateTime start    = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
            OffsetDateTime end      = new LocalDateTime(2014, 08, 14, 18, 0).WithOffset(Offset.FromHours(4));
            Duration       expected = Duration.FromHours(8) + Duration.FromMinutes(9);

            Assert.AreEqual(expected, end - start);
            Assert.AreEqual(expected, end.Minus(start));
            Assert.AreEqual(expected, OffsetDateTime.Subtract(end, start));
        }
        public void Minus_FullPeriod()
        {
            // Period deliberately chosen to require date rollover
            LocalDateTime start  = new LocalDateTime(2011, 4, 2, 12, 15, 8);
            var           period = new PeriodBuilder {
                Years   = 1, Months = 2, Weeks = 3, Days = 4, Hours = 15, Minutes = 6,
                Seconds = 7, Milliseconds = 8, Ticks = 9, Nanoseconds = 11
            }.Build();
            var actual   = start.Minus(period);
            var expected = new LocalDateTime(2010, 1, 7, 21, 9, 0).PlusNanoseconds(991999089L);

            Assert.AreEqual(expected, actual, $"{expected:yyyy-MM-dd HH:mm:ss.fffffffff} != {actual:yyyy-MM-dd HH:mm:ss.fffffffff}");
        }
Beispiel #11
0
 public Tick(Period _timePeriod, LocalDateTime _endTime, Decimal _openPrice, Decimal _maxPrice, Decimal _minPrice, Decimal _closePrice, Decimal _volume, Decimal _amount, int _trades)
 {
     CheckTimeArguments(_timePeriod, _endTime);
     this._timePeriod = _timePeriod;
     this._endTime    = _endTime;
     this._beginTime  = _endTime.Minus(_timePeriod);
     this._openPrice  = _openPrice;
     this._maxPrice   = _maxPrice;
     this._minPrice   = _minPrice;
     this._closePrice = _closePrice;
     this._volume     = _volume;
     this._amount     = _amount;
     this._trades     = _trades;
 }
Beispiel #12
0
        public void Operator_MethodEquivalents()
        {
            LocalDateTime start  = new LocalDateTime(2011, 1, 1, 15, 25, 30).PlusNanoseconds(123456789);
            Period        period = Period.FromHours(1) + Period.FromDays(1);
            LocalDateTime end    = start + period;

            Assert.AreEqual(start + period, LocalDateTime.Add(start, period));
            Assert.AreEqual(start + period, start.Plus(period));
            Assert.AreEqual(start - period, LocalDateTime.Subtract(start, period));
            Assert.AreEqual(start - period, start.Minus(period));
            Assert.AreEqual(period, end - start);
            Assert.AreEqual(period, LocalDateTime.Subtract(end, start));
            Assert.AreEqual(period, end.Minus(start));
        }
        public void Can_Query_By_GreaterThan_LocalDateTime_Stored_As_DateTime2()
        {
            var           timeZone            = DateTimeZoneProviders.Tzdb.GetSystemDefault();
            LocalDateTime startLocalDateTime  = TestClock.Now.InZone(timeZone).LocalDateTime.Plus(Period.FromHours(1));
            LocalDateTime finishLocalDateTime = startLocalDateTime.PlusHours(3);
            var           testEvent           = new LocalDateTimeTestEntity
            {
                Description         = "Can_Query_By_GreaterThan_LocalDateTime_Stored_As_DateTime2",
                StartLocalDateTime  = startLocalDateTime,
                FinishLocalDateTime = finishLocalDateTime
            };

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(testEvent);
                    transaction.Commit();
                }

            LocalDateTime beforeLocalDateTime = startLocalDateTime.Minus(Period.FromHours(1));

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var query = session.Query <LocalDateTimeTestEntity>()
                                .Where(x => x.Id == testEvent.Id && x.StartLocalDateTime > beforeLocalDateTime);
                    var retrievedEvent = query.SingleOrDefault();
                    transaction.Commit();
                    Assert.That(testEvent, Is.Not.Null);
                    Assert.That(testEvent, Is.EqualTo(retrievedEvent));
                }

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var query = session.Query <LocalDateTimeTestEntity>()
                                .Where(x => x.Id == testEvent.Id && x.StartLocalDateTime > beforeLocalDateTime && x.FinishLocalDateTime >= finishLocalDateTime);
                    var retrievedEvent = query.SingleOrDefault();
                    transaction.Commit();
                    Assert.That(testEvent, Is.Not.Null);
                    Assert.That(testEvent, Is.EqualTo(retrievedEvent));
                }
        }
 public void Subtraction_OffsetDateTime()
 {
     // Test all three approaches... not bothering to check a different calendar,
     // but we'll use two different offsets.
     OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
     OffsetDateTime end = new LocalDateTime(2014, 08, 14, 18, 0).WithOffset(Offset.FromHours(4));
     Duration expected = Duration.FromHours(8) + Duration.FromMinutes(9);
     Assert.AreEqual(expected, end - start);
     Assert.AreEqual(expected, end.Minus(start));
     Assert.AreEqual(expected, OffsetDateTime.Subtract(end, start));
 }
 public void Operator_MethodEquivalents()
 {
     LocalDateTime start = new LocalDateTime(2011, 1, 1, 15, 25, 30, 100, 5000);
     Period period = Period.FromHours(1) + Period.FromDays(1);
     LocalDateTime end = start + period;
     Assert.AreEqual(start + period, LocalDateTime.Add(start, period));
     Assert.AreEqual(start + period, start.Plus(period));
     Assert.AreEqual(start - period, LocalDateTime.Subtract(start, period));
     Assert.AreEqual(start - period, start.Minus(period));
     Assert.AreEqual(period, end - start);
     Assert.AreEqual(period, LocalDateTime.Subtract(end, start));
     Assert.AreEqual(period, end.Minus(start));
 }