Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowExceptionOnSubtractOverflow()
        internal virtual void ShouldThrowExceptionOnSubtractOverflow()
        {
            DurationValue duration1 = duration(0, 0, long.MinValue, 0);
            DurationValue duration2 = duration(0, 0, 1, 0);

            assertThrows(typeof(InvalidValuesArgumentException), () => duration1.Sub(duration2));
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowExceptionOnMultiplyOverflow()
        internal virtual void ShouldThrowExceptionOnMultiplyOverflow()
        {
            DurationValue duration = duration(0, 0, long.MaxValue, 0);

            assertThrows(typeof(InvalidValuesArgumentException), () => duration.Mul(Values.IntValue(2)));
            assertThrows(typeof(InvalidValuesArgumentException), () => duration.Mul(Values.FloatValue(2)));
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseInstanceInArithmetics()
        public virtual void ShouldReuseInstanceInArithmetics()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final DateTimeValue datetime = datetime(date(2018, 2, 1), time(1, 17, 3, 0, UTC));
            DateTimeValue datetime = datetime(date(2018, 2, 1), time(1, 17, 3, 0, UTC));

            assertSame(datetime, datetime.Add(DurationValue.Duration(0, 0, 0, 0)));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApproximateWithoutAccumulatedRoundingErrors2()
        public virtual void ShouldApproximateWithoutAccumulatedRoundingErrors2()
        {
            double        months = 1.9013243104086859E-16; // 0.5 ns
            double        nanos  = 0.6;                    // with 1.1 ns we should be on the safe side to get rounded to 1 ns, even with rounding errors
            DurationValue result = DurationValue.Approximate(months, 0, 0, nanos);

            assertEqual(result, DurationValue.Duration(0, 0, 0, 1));
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowExceptionOnAddOverflow()
        internal virtual void ShouldThrowExceptionOnAddOverflow()
        {
            DurationValue duration1 = duration(0, 0, long.MaxValue, 500_000_000);
            DurationValue duration2 = duration(0, 0, 1, 0);
            DurationValue duration3 = duration(0, 0, 0, 500_000_000);

            assertThrows(typeof(InvalidValuesArgumentException), () => duration1.Add(duration2));
            assertThrows(typeof(InvalidValuesArgumentException), () => duration1.Add(duration3));
        }
Exemplo n.º 6
0
 public static DurationArray DurationArray(TemporalAmount[] values)
 {
     DurationValue[] durations = new DurationValue[values.Length];
     for (int i = 0; i < values.Length; i++)
     {
         durations[i] = DurationValue(values[i]);
     }
     return(new DurationArray(durations));
 }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReuseInstanceInArithmetics()
        internal virtual void ShouldReuseInstanceInArithmetics()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final DateValue date = date(2018, 2, 1);
            DateValue date = date(2018, 2, 1);

            assertSame(date, date.Add(DurationValue.Duration(0, 0, 0, 0)));
            assertSame(date, date.Add(DurationValue.Duration(0, 0, 1, 1)));
            assertSame(date, date.Add(DurationValue.Duration(-0, 0, 1, -1)));
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReuseInstanceInArithmetics()
        internal virtual void ShouldReuseInstanceInArithmetics()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TimeValue noon = time(12, 0, 0, 0, UTC);
            TimeValue noon = time(12, 0, 0, 0, UTC);

            assertSame(noon, noon.Add(DurationValue.Duration(0, 0, 0, 0)));
            assertSame(noon, noon.Add(DurationValue.Duration(1, 1, 0, 0)));
            assertSame(noon, noon.Add(DurationValue.Duration(-1, 1, 0, -0)));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNormalizeNanoseconds()
        internal virtual void ShouldNormalizeNanoseconds()
        {
            // given
            DurationValue evenPos = duration(0, 0, 0, 1_000_000_000);
            DurationValue evenNeg = duration(0, 0, 0, -1_000_000_000);
            DurationValue pos     = duration(0, 0, 0, 1_500_000_000);
            DurationValue neg     = duration(0, 0, 0, -1_400_000_000);

            // then
            assertEquals(500_000_000, pos.get(NANOS), "+nanos");
            assertEquals(1, pos.get(SECONDS), "+seconds");
            assertEquals(600_000_000, neg.get(NANOS), "+nanos");
            assertEquals(-2, neg.get(SECONDS), "-seconds");

            assertEquals(0, evenPos.get(NANOS), "+nanos");
            assertEquals(1, evenPos.get(SECONDS), "+seconds");
            assertEquals(0, evenNeg.get(NANOS), "+nanos");
            assertEquals(-1, evenNeg.get(SECONDS), "-seconds");
        }
Exemplo n.º 10
0
        public static DurationValue DurationValue(TemporalAmount value)
        {
            if (value is Duration)
            {
                return(duration(( Duration )value));
            }
            if (value is Period)
            {
                return(duration(( Period )value));
            }
            if (value is DurationValue)
            {
                return(( DurationValue )value);
            }
            DurationValue duration = duration(0, 0, 0, 0);

            foreach (TemporalUnit unit in value.Units)
            {
                duration = duration.Plus(value.get(unit), unit);
            }
            return(duration);
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNormalizeSecondsAndNanos()
        internal virtual void ShouldNormalizeSecondsAndNanos()
        {
            // given
            DurationValue pos = duration(0, 0, 5, -1_400_000_000);
            DurationValue neg = duration(0, 0, -5, 1_500_000_000);
            DurationValue x   = duration(0, 0, 1, -1_400_000_000);

            DurationValue y  = duration(0, 0, -59, -500_000_000);
            DurationValue y2 = duration(0, 0, -60, 500_000_000);

            // then
            assertEquals(600_000_000, pos.get(NANOS), "+nanos");
            assertEquals(3, pos.get(SECONDS), "+seconds");
            assertEquals(500_000_000, neg.get(NANOS), "+nanos");
            assertEquals(-4, neg.get(SECONDS), "-seconds");
            assertEquals(600_000_000, x.get(NANOS), "+nanos");
            assertEquals(-1, x.get(SECONDS), "-seconds");
            assertEquals(500_000_000, y.get(NANOS), "+nanos");
            assertEquals(-60, y.get(SECONDS), "-seconds");
            assertEquals(500_000_000, y2.get(NANOS), "+nanos");
            assertEquals(-60, y2.get(SECONDS), "-seconds");
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGetSameInstantWhenAddingDurationBetweenToInstant()
        internal virtual void ShouldGetSameInstantWhenAddingDurationBetweenToInstant()
        {
            // given
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") org.neo4j.helpers.collection.Pair<java.time.temporal.Temporal, java.time.temporal.Temporal>[] input = new org.neo4j.helpers.collection.Pair[]{ pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), java.time.ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(19, 40, 0, 0), java.time.ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), java.time.ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(11, 40, 0, 0), java.time.ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), java.time.ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(19, 40, 0, 0), java.time.ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), java.time.ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(11, 40, 0, 0), java.time.ZoneId.of("Europe/Stockholm")))};
            Pair <Temporal, Temporal>[] input = new Pair[] { pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(19, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 3, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 3, 26), localTime(11, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(19, 40, 0, 0), ZoneId.of("Europe/Stockholm"))), pair(datetime(date(2017, 10, 20), localTime(13, 37, 0, 0), ZoneId.of("Europe/Stockholm")), datetime(date(2017, 10, 29), localTime(11, 40, 0, 0), ZoneId.of("Europe/Stockholm"))) };
            foreach (Pair <Temporal, Temporal> pair in input)
            {
                Temporal a = pair.First(), b = pair.Other();

                // when
                DurationValue diffAB  = durationBetween(a, b);
                DurationValue diffBA  = durationBetween(b, a);
                DurationValue diffABs = between(SECONDS, a, b);
                DurationValue diffBAs = between(SECONDS, b, a);

                // then
                assertEquals(b, a.plus(diffAB), diffAB.PrettyPrint());
                assertEquals(a, b.plus(diffBA), diffBA.PrettyPrint());
                assertEquals(b, a.plus(diffABs), diffABs.PrettyPrint());
                assertEquals(a, b.plus(diffBAs), diffBAs.PrettyPrint());
            }
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddDurationToTimes()
        internal virtual void ShouldAddDurationToTimes()
        {
            assertEquals(time(12, 15, 0, 0, UTC), time(12, 0, 0, 0, UTC).add(DurationValue.Duration(1, 1, 900, 0)));
            assertEquals(time(12, 0, 2, 0, UTC), time(12, 0, 0, 0, UTC).add(DurationValue.Duration(0, 0, 1, 1_000_000_000)));
            assertEquals(time(12, 0, 0, 0, UTC), time(12, 0, 0, 0, UTC).add(DurationValue.Duration(0, 0, 1, -1_000_000_000)));
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSubtractDurationFromDateTimes()
        public virtual void ShouldSubtractDurationFromDateTimes()
        {
            assertEquals(datetime(date(2018, 1, 1), time(1, 2, 3, 0, UTC)), datetime(date(2018, 2, 1), time(1, 17, 3, 0, UTC)).sub(DurationValue.Duration(1, 0, 900, 0)));
            assertEquals(datetime(date(2018, 1, 28), time(0, 0, 0, 0, UTC)), datetime(date(2018, 2, 28), time(0, 0, 0, 0, UTC)).sub(DurationValue.Duration(1, 0, 0, 0)));
            assertEquals(datetime(date(2018, 2, 28), time(0, 0, 0, 0, UTC)), datetime(date(2018, 1, 31), time(0, 0, 0, 0, UTC)).sub(DurationValue.Duration(-1, 0, 0, 0)));
        }
Exemplo n.º 15
0
 public override DateTimeValue Add(DurationValue duration)
 {
     return(Replacement(AssertValidArithmetic(() => _value.plus(duration))));
 }
Exemplo n.º 16
0
 public override TimeValue Sub(DurationValue duration)
 {
     return(Replacement(AssertValidArithmetic(() => _value.minusNanos(duration.NanosOfDay()))));
 }
Exemplo n.º 17
0
 public override LocalDateTimeValue Sub(DurationValue duration)
 {
     return(Replacement(AssertValidArithmetic(() => _value.minus(duration))));
 }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApproximateWithoutAccumulatedRoundingErrors()
        public virtual void ShouldApproximateWithoutAccumulatedRoundingErrors()
        {
            DurationValue result = DurationValue.Approximate(10.8, 0, 0, 0);

            assertEqual(result, DurationValue.Duration(10, 24, 30196, 800000000));
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleLargeNanos()
        internal virtual void ShouldHandleLargeNanos()
        {
            DurationValue duration = DurationValue.Duration(0L, 0L, 0L, long.MaxValue);

            assertEquals(long.MaxValue, duration.Get("nanoseconds").value());
        }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddDurationToDateTimes()
        public virtual void ShouldAddDurationToDateTimes()
        {
            assertEquals(datetime(date(2018, 2, 1), time(1, 17, 3, 0, UTC)), datetime(date(2018, 1, 1), time(1, 2, 3, 0, UTC)).add(DurationValue.Duration(1, 0, 900, 0)));
            assertEquals(datetime(date(2018, 2, 28), time(0, 0, 0, 0, UTC)), datetime(date(2018, 1, 31), time(0, 0, 0, 0, UTC)).add(DurationValue.Duration(1, 0, 0, 0)));
            assertEquals(datetime(date(2018, 1, 28), time(0, 0, 0, 0, UTC)), datetime(date(2018, 2, 28), time(0, 0, 0, 0, UTC)).add(DurationValue.Duration(-1, 0, 0, 0)));
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSubtractDurationFromTimes()
        internal virtual void ShouldSubtractDurationFromTimes()
        {
            assertEquals(time(12, 0, 0, 0, UTC), time(12, 15, 0, 0, UTC).sub(DurationValue.Duration(1, 1, 900, 0)));
            assertEquals(time(12, 0, 0, 0, UTC), time(12, 0, 2, 0, UTC).sub(DurationValue.Duration(0, 0, 1, 1_000_000_000)));
            assertEquals(time(12, 0, 0, 0, UTC), time(12, 0, 0, 0, UTC).sub(DurationValue.Duration(0, 0, 1, -1_000_000_000)));
        }
Exemplo n.º 22
0
 public override void WriteDuration(long months, long days, long seconds, int nanos)
 {
     Buffer.Add(DurationValue.Duration(months, days, seconds, nanos));
 }
Exemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddDurationToDates()
        internal virtual void ShouldAddDurationToDates()
        {
            assertEquals(date(2018, 2, 1), date(2018, 1, 1).add(DurationValue.Duration(1, 0, 900, 0)));
            assertEquals(date(2018, 2, 28), date(2018, 1, 31).add(DurationValue.Duration(1, 0, 0, 0)));
            assertEquals(date(2018, 1, 28), date(2018, 2, 28).add(DurationValue.Duration(-1, 0, 0, 0)));
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowExceptionOnDivideOverflow()
        internal virtual void ShouldThrowExceptionOnDivideOverflow()
        {
            DurationValue duration = duration(0, 0, long.MaxValue, 0);

            assertThrows(typeof(InvalidValuesArgumentException), () => duration.Div(Values.FloatValue(0.5f)));
        }
Exemplo n.º 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSubtractDurationFromDates()
        internal virtual void ShouldSubtractDurationFromDates()
        {
            assertEquals(date(2018, 1, 1), date(2018, 2, 1).sub(DurationValue.Duration(1, 0, 900, 0)));
            assertEquals(date(2018, 1, 28), date(2018, 2, 28).sub(DurationValue.Duration(1, 0, 0, 0)));
            assertEquals(date(2018, 2, 28), date(2018, 1, 31).sub(DurationValue.Duration(-1, 0, 0, 0)));
        }
Exemplo n.º 26
0
 public override DateValue Sub(DurationValue duration)
 {
     return(Replacement(AssertValidArithmetic(() => _value.minusMonths(duration.TotalMonths()).minusDays(duration.TotalDays()))));
 }
Exemplo n.º 27
0
 public override LocalTimeValue Add(DurationValue duration)
 {
     return(Replacement(AssertValidArithmetic(() => _value.plusNanos(duration.NanosOfDay()))));
 }