Beispiel #1
0
        public void ejecutarCodigo()
        {
            Temporal p = new Temporal("P", 0);
            Temporal H = new Temporal("H", 0);

            temporales.agregarTemp(p);
            temporales.agregarTemp(H);

            ParseTreeNode metodoTemporal, cuerpoTemporal;

            for (int i = 0; i < raiz3D.ChildNodes.Count; i++)
            {
                metodoTemporal = raiz3D.ChildNodes[i];
                if (metodoTemporal.ChildNodes[0].Token.ValueString.Equals(metodoInicio, StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("entre al principal ");
                    cuerpoTemporal = metodoTemporal.ChildNodes[1];
                    for (int j = 0; j < cuerpoTemporal.ChildNodes.Count; j++)
                    {
                        if (bandera == 1)
                        {
                            break;
                        }
                        ejecutarInstruccion(cuerpoTemporal.ChildNodes[j]);
                    }
                }
            }
        }
        /// <summary>
        /// Returns the day-of-week in month adjuster, which returns a new date
        /// in the same month with the ordinal day-of-week.
        /// This is used for expressions like the 'second Tuesday in March'.
        /// <para>
        /// The ISO calendar system behaves as follows:<br>
        /// The input 2011-12-15 for (1,TUESDAY) will return 2011-12-06.<br>
        /// The input 2011-12-15 for (2,TUESDAY) will return 2011-12-13.<br>
        /// The input 2011-12-15 for (3,TUESDAY) will return 2011-12-20.<br>
        /// The input 2011-12-15 for (4,TUESDAY) will return 2011-12-27.<br>
        /// The input 2011-12-15 for (5,TUESDAY) will return 2012-01-03.<br>
        /// The input 2011-12-15 for (-1,TUESDAY) will return 2011-12-27 (last in month).<br>
        /// The input 2011-12-15 for (-4,TUESDAY) will return 2011-12-06 (3 weeks before last in month).<br>
        /// The input 2011-12-15 for (-5,TUESDAY) will return 2011-11-29 (4 weeks before last in month).<br>
        /// The input 2011-12-15 for (0,TUESDAY) will return 2011-11-29 (last in previous month).<br>
        /// </para>
        /// <para>
        /// For a positive or zero ordinal, the algorithm is equivalent to finding the first
        /// day-of-week that matches within the month and then adding a number of weeks to it.
        /// For a negative ordinal, the algorithm is equivalent to finding the last
        /// day-of-week that matches within the month and then subtracting a number of weeks to it.
        /// The ordinal number of weeks is not validated and is interpreted leniently
        /// according to this algorithm. This definition means that an ordinal of zero finds
        /// the last matching day-of-week in the previous month.
        /// </para>
        /// <para>
        /// The behavior is suitable for use with most calendar systems.
        /// It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields
        /// and the {@code DAYS} unit, and assumes a seven day week.
        ///
        /// </para>
        /// </summary>
        /// <param name="ordinal">  the week within the month, unbounded but typically from -5 to 5 </param>
        /// <param name="dayOfWeek">  the day-of-week, not null </param>
        /// <returns> the day-of-week in month adjuster, not null </returns>
        public static TemporalAdjuster DayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek)
        {
            Objects.RequireNonNull(dayOfWeek, "dayOfWeek");
            int dowValue = dayOfWeek.Value;

            if (ordinal >= 0)
            {
//JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate:
                return((temporal) =>
                {
                    Temporal temp = temporal.with(DAY_OF_MONTH, 1);
                    int curDow = temp.get(DAY_OF_WEEK);
                    int dowDiff = (dowValue - curDow + 7) % 7;
                    dowDiff += (int)((ordinal - 1L) * 7L);                     // safe from overflow
                    return temp.Plus(dowDiff, DAYS);
                });
            }
            else
            {
//JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate:
                return((temporal) =>
                {
                    Temporal temp = temporal.with(DAY_OF_MONTH, temporal.range(DAY_OF_MONTH).Maximum);
                    int curDow = temp.get(DAY_OF_WEEK);
                    int daysDiff = dowValue - curDow;
                    daysDiff = (daysDiff == 0 ? 0 : (daysDiff > 0 ? daysDiff - 7 : daysDiff));
                    daysDiff -= (int)((-ordinal - 1L) * 7L);                     // safe from overflow
                    return temp.Plus(daysDiff, DAYS);
                });
            }
        }
Beispiel #3
0
        public static DurationValue Between(TemporalUnit unit, Temporal from, Temporal to)
        {
            if (unit == null)
            {
                return(DurationBetween(from, to));
            }
            else if (unit is ChronoUnit)
            {
                switch (( ChronoUnit )unit)
                {
                case MONTHS:
                    return(NewDuration(AssertValidUntil(from, to, unit), 0, 0, 0));

                case DAYS:
                    return(NewDuration(0, AssertValidUntil(from, to, unit), 0, 0));

                case SECONDS:
                    return(DurationInSecondsAndNanos(from, to));

                default:
                    throw new UnsupportedTemporalUnitException("Unsupported unit: " + unit);
                }
            }
            else
            {
                throw new UnsupportedTemporalUnitException("Unsupported unit: " + unit);
            }
        }
Beispiel #4
0
        internal static DurationValue DurationBetween(Temporal from, Temporal to)
        {
            long months = 0;
            long days   = 0;

            if (from.isSupported(EPOCH_DAY) && to.isSupported(EPOCH_DAY))
            {
                months = AssertValidUntil(from, to, ChronoUnit.MONTHS);
                try
                {
                    from = from.plus(months, ChronoUnit.MONTHS);
                }
                catch (Exception e) when(e is DateTimeException || e is ArithmeticException)
                {
                    throw new TemporalArithmeticException(e.Message, e);
                }

                days = AssertValidUntil(from, to, ChronoUnit.DAYS);
                try
                {
                    from = from.plus(days, ChronoUnit.DAYS);
                }
                catch (Exception e) when(e is DateTimeException || e is ArithmeticException)
                {
                    throw new TemporalArithmeticException(e.Message, e);
                }
            }
            long nanos = AssertValidUntil(from, to, NANOS);

            return(NewDuration(months, days, nanos / NANOS_PER_SECOND, nanos % NANOS_PER_SECOND));
        }
Beispiel #5
0
 public Temporal SubtractFrom(Temporal temporal)
 {
     ValidateChrono(temporal);
     if (Months == 0)
     {
         if (Years != 0)
         {
             temporal = temporal.minus(Years, YEARS);
         }
     }
     else
     {
         long monthRange = MonthRange();
         if (monthRange > 0)
         {
             temporal = temporal.minus(Years * monthRange + Months, MONTHS);
         }
         else
         {
             if (Years != 0)
             {
                 temporal = temporal.minus(Years, YEARS);
             }
             temporal = temporal.minus(Months, MONTHS);
         }
     }
     if (Days != 0)
     {
         temporal = temporal.minus(Days, DAYS);
     }
     return(temporal);
 }
Beispiel #6
0
 public override Temporal SubtractFrom(Temporal temporal)
 {
     if (_months != 0 && temporal.isSupported(MONTHS))
     {
         temporal = AssertValidMinus(temporal, _months, MONTHS);
     }
     if (_days != 0 && temporal.isSupported(DAYS))
     {
         temporal = AssertValidMinus(temporal, _days, DAYS);
     }
     if (_seconds != 0)
     {
         if (temporal.isSupported(SECONDS))
         {
             temporal = AssertValidMinus(temporal, _seconds, SECONDS);
         }
         else if (temporal.isSupported(DAYS))
         {
             long asDays = _seconds / SECONDS_PER_DAY;
             if (asDays != 0)
             {
                 temporal = AssertValidMinus(temporal, asDays, DAYS);
             }
         }
     }
     if (_nanos != 0 && temporal.isSupported(NANOS))
     {
         temporal = AssertValidMinus(temporal, _nanos, NANOS);
     }
     return(temporal);
 }
Beispiel #7
0
        static public bool IsStopped(this Temporal item)
        {
            if (item.IsRunning() == false)
            {
                return(true);
            }

            return(false);
        }
Beispiel #8
0
 /// <summary>
 /// Adjusts the specified temporal object to have this month-day.
 /// <para>
 /// This returns a temporal object of the same observable type as the input
 /// with the month and day-of-month changed to be the same as this.
 /// </para>
 /// <para>
 /// The adjustment is equivalent to using <seealso cref="Temporal#with(TemporalField, long)"/>
 /// twice, passing <seealso cref="ChronoField#MONTH_OF_YEAR"/> and
 /// <seealso cref="ChronoField#DAY_OF_MONTH"/> as the fields.
 /// If the specified temporal object does not use the ISO calendar system then
 /// a {@code DateTimeException} is thrown.
 /// </para>
 /// <para>
 /// In most cases, it is clearer to reverse the calling pattern by using
 /// <seealso cref="Temporal#with(TemporalAdjuster)"/>:
 /// <pre>
 ///   // these two lines are equivalent, but the second approach is recommended
 ///   temporal = thisMonthDay.adjustInto(temporal);
 ///   temporal = temporal.with(thisMonthDay);
 /// </pre>
 /// </para>
 /// <para>
 /// This instance is immutable and unaffected by this method call.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the target object to be adjusted, not null </param>
 /// <returns> the adjusted object, not null </returns>
 /// <exception cref="DateTimeException"> if unable to make the adjustment </exception>
 /// <exception cref="ArithmeticException"> if numeric overflow occurs </exception>
 public Temporal AdjustInto(Temporal temporal)
 {
     if (Chronology.from(temporal).Equals(IsoChronology.INSTANCE) == false)
     {
         throw new DateTimeException("Adjustment only supported on ISO date-time");
     }
     temporal = temporal.With(MONTH_OF_YEAR, Month_Renamed);
     return(temporal.With(DAY_OF_MONTH, System.Math.Min(temporal.range(DAY_OF_MONTH).Maximum, Day)));
 }
 /// <summary>
 /// Adds this tenor to the specified date.
 /// <para>
 /// This method implements <seealso cref="TemporalAmount"/>.
 /// It is not intended to be called directly.
 /// Use <seealso cref="LocalDate#plus(TemporalAmount)"/> instead.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to add to </param>
 /// <returns> the result with this tenor added </returns>
 /// <exception cref="DateTimeException"> if unable to add </exception>
 /// <exception cref="ArithmeticException"> if numeric overflow occurs </exception>
 public override Temporal addTo(Temporal temporal)
 {
     // special case for performance
     if (temporal is LocalDate)
     {
         LocalDate date = (LocalDate)temporal;
         return(plusDays(date.plusMonths(period.toTotalMonths()), period.Days));
     }
     return(period.addTo(temporal));
 }
 /// <summary>
 /// Subtracts this tenor from the specified date.
 /// <para>
 /// This method implements <seealso cref="TemporalAmount"/>.
 /// It is not intended to be called directly.
 /// Use <seealso cref="LocalDate#minus(TemporalAmount)"/> instead.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to subtract from </param>
 /// <returns> the result with this tenor subtracted </returns>
 /// <exception cref="DateTimeException"> if unable to subtract </exception>
 /// <exception cref="ArithmeticException"> if numeric overflow occurs </exception>
 public override Temporal subtractFrom(Temporal temporal)
 {
     // special case for performance
     if (temporal is LocalDate)
     {
         LocalDate date = (LocalDate)temporal;
         return(plusDays(date.minusMonths(period.toTotalMonths()), -period.Days));
     }
     return(period.subtractFrom(temporal));
 }
Beispiel #11
0
 public static void AgregarTemporal(string sProceso, int iId, string sValor)
 {
     var oTemp = new Temporal()
     {
         Proceso = sProceso,
         Identificador = iId,
         Valor = sValor
     };
     Datos.Guardar<Temporal>(oTemp);
 }
Beispiel #12
0
        /// <summary>
        /// Returns a copy of this date-time with the new date and time, checking
        /// to see if a new object is in fact required.
        /// </summary>
        /// <param name="newDate">  the date of the new date-time, not null </param>
        /// <param name="newTime">  the time of the new date-time, not null </param>
        /// <returns> the date-time, not null </returns>
        private ChronoLocalDateTimeImpl <D> With(Temporal newDate, LocalTime newTime)
        {
            if (Date == newDate && Time == newTime)
            {
                return(this);
            }
            // Validate that the new Temporal is a ChronoLocalDate (and not something else)
            D cd = ChronoLocalDateImpl.EnsureValid(Date.Chronology, newDate);

            return(new ChronoLocalDateTimeImpl <>(cd, newTime));
        }
Beispiel #13
0
        public static void AgregarTemporal(string sProceso, int iId, string sValor)
        {
            var oTemp = new Temporal()
            {
                Proceso       = sProceso,
                Identificador = iId,
                Valor         = sValor
            };

            Datos.Guardar <Temporal>(oTemp);
        }
Beispiel #14
0
        //-----------------------------------------------------------------------
        public long Until(Temporal endExclusive, TemporalUnit unit)
        {
            Objects.RequireNonNull(endExclusive, "endExclusive");
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
            ChronoLocalDateTime <D> end = (ChronoLocalDateTime <D>)Chronology.localDateTime(endExclusive);

            if (unit is ChronoUnit)
            {
                if (unit.TimeBased)
                {
                    long amount = end.getLong(EPOCH_DAY) - Date.GetLong(EPOCH_DAY);
                    switch ((ChronoUnit)unit)
                    {
                    case NANOS:
                        amount = Math.MultiplyExact(amount, NANOS_PER_DAY);
                        break;

                    case MICROS:
                        amount = Math.MultiplyExact(amount, MICROS_PER_DAY);
                        break;

                    case MILLIS:
                        amount = Math.MultiplyExact(amount, MILLIS_PER_DAY);
                        break;

                    case SECONDS:
                        amount = Math.MultiplyExact(amount, SECONDS_PER_DAY);
                        break;

                    case MINUTES:
                        amount = Math.MultiplyExact(amount, MINUTES_PER_DAY);
                        break;

                    case HOURS:
                        amount = Math.MultiplyExact(amount, HOURS_PER_DAY);
                        break;

                    case HALF_DAYS:
                        amount = Math.MultiplyExact(amount, 2);
                        break;
                    }
                    return(Math.AddExact(amount, Time.Until(end.ToLocalTime(), unit)));
                }
                ChronoLocalDate endDate = end.ToLocalDate();
                if (end.ToLocalTime().IsBefore(Time))
                {
                    endDate = endDate.minus(1, ChronoUnit.DAYS);
                }
                return(Date.Until(endDate, unit));
            }
            Objects.RequireNonNull(unit, "unit");
            return(unit.Between(this, end));
        }
Beispiel #15
0
 private static Temporal AssertValidMinus(Temporal temporal, long amountToAdd, TemporalUnit unit)
 {
     try
     {
         return(temporal.minus(amountToAdd, unit));
     }
     catch (Exception e) when(e is DateTimeException || e is ArithmeticException)
     {
         throw new TemporalArithmeticException(e.Message, e);
     }
 }
Beispiel #16
0
        /// <summary>
        /// Casts the {@code Temporal} to {@code ChronoLocalDate} ensuring it bas the specified chronology.
        /// </summary>
        /// <param name="chrono">  the chronology to check for, not null </param>
        /// <param name="temporal">  a date-time to cast, not null </param>
        /// <returns> the date-time checked and cast to {@code ChronoLocalDate}, not null </returns>
        /// <exception cref="ClassCastException"> if the date-time cannot be cast to ChronoLocalDate
        ///  or the chronology is not equal this Chronology </exception>
        internal static D ensureValid <D>(Chronology ChronoLocalDate_Fields, Temporal temporal) where D : ChronoLocalDate
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") D other = (D) temporal;
            D other = (D)temporal;

            if (ChronoLocalDate_Fields.Chrono.Equals(other.Chronology) == false)
            {
                throw new ClassCastException("Chronology mismatch, expected: " + ChronoLocalDate_Fields.Chrono.Id + ", actual: " + other.Chronology.Id);
            }
            return(other);
        }
Beispiel #17
0
 public void Merge(AtomAdditionalInfo defaults)
 {
     HasHiddenPrimaryKey = HasHiddenPrimaryKey ?? defaults.HasHiddenPrimaryKey;
     AutoGenId = AutoGenId ?? defaults.AutoGenId;
     FilterDeleted = FilterDeleted ?? defaults.FilterDeleted;
     UseSoftDeletes = UseSoftDeletes ?? defaults.UseSoftDeletes;
     UseWithNoLockHint = UseWithNoLockHint ?? defaults.UseWithNoLockHint;
     GenerateCode = GenerateCode ?? defaults.GenerateCode ?? true;
     Schema = Schema ?? defaults.Schema ?? Constants.DefaultSchema;
     GenerateLookupData = GenerateLookupData ?? defaults.GenerateLookupData;
     Temporal.Merge(defaults.Temporal);
     MergeQueryTypes(defaults);
 }
		//-----------------------------------------------------------------------
		public override long Until(Temporal endExclusive, TemporalUnit unit)
		{
			Objects.RequireNonNull(endExclusive, "endExclusive");
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) getChronology().zonedDateTime(endExclusive);
			ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) Chronology.zonedDateTime(endExclusive);
			if (unit is ChronoUnit)
			{
				end = end.WithZoneSameInstant(Offset_Renamed);
				return DateTime.Until(end.ToLocalDateTime(), unit);
			}
			Objects.RequireNonNull(unit, "unit");
			return unit.Between(this, end);
		}
Beispiel #19
0
 private static long AssertValidUntil(Temporal from, Temporal to, TemporalUnit unit)
 {
     try
     {
         return(from.until(to, unit));
     }
     catch (UnsupportedTemporalTypeException e)
     {
         throw new UnsupportedTemporalUnitException(e.Message, e);
     }
     catch (DateTimeException e)
     {
         throw new InvalidValuesArgumentException(e.Message, e);
     }
 }
Beispiel #20
0
        private void asignacionNormal(ParseTreeNode nodo)
        {
            // asignacionNormal.Rule = identificador + ToTerm("=") + EXPRESION + ";";
            string   idTemp = nodo.ChildNodes[0].Token.ValueString;
            Object   val    = resolverExp(nodo.ChildNodes[1]);
            Temporal nuevo  = new Temporal(idTemp, val);

            if (idTemp.Equals("P", StringComparison.OrdinalIgnoreCase))
            {
                temporales.modificarTemp(nuevo);
            }
            else
            {
                temporales.agregarTemp(nuevo);
            }
        }
Beispiel #21
0
        public void StopWatch()
        {
            StopWatch stopwatch = new StopWatch();

            stopwatch.Start();
            Temporal.PauseExecution(2000);
            stopwatch.Stop();

            Assert.AreEqual(2, stopwatch.GetSeconds <int>(), "GetSeconds()");

            stopwatch.StopDate = stopwatch.StartDate.AddSeconds(1);
            Assert.AreEqual("00:00:01", stopwatch.GetTimeSpan().ToString(@"hh\:mm\:ss"), "GetTimeSpan() 1 second");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(1);
            Assert.AreEqual("1.00:00:00", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss"), "GetTimeSpan() 1 day");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(3).AddHours(5).AddMinutes(7).AddSeconds(15);
            Assert.AreEqual("3.05:07:15", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss"), "GetTimeSpan() complex");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(3).AddHours(5).AddMinutes(7).AddSeconds(15).AddMilliseconds(999);
            Assert.AreEqual("3.05:07:15.999", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss\.fff"), "GetTimeSpan() complex 2");
        }
Beispiel #22
0
        //-----------------------------------------------------------------------
        public virtual long Until(Temporal endExclusive, TemporalUnit unit)
        {
            Objects.RequireNonNull(endExclusive, "endExclusive");
            ChronoLocalDate end = Chronology.Date(endExclusive);

            if (unit is ChronoUnit)
            {
                switch ((ChronoUnit)unit)
                {
                case DAYS:
                    return(DaysUntil(end));

                case WEEKS:
                    return(DaysUntil(end) / 7);

                case MONTHS:
                    return(MonthsUntil(end));

                case YEARS:
                    return(MonthsUntil(end) / 12);

                case DECADES:
                    return(MonthsUntil(end) / 120);

                case CENTURIES:
                    return(MonthsUntil(end) / 1200);

                case MILLENNIA:
                    return(MonthsUntil(end) / 12000);

                case ERAS:
                    return(end.GetLong(ERA) - GetLong(ERA));
                }
                throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
            }
            Objects.RequireNonNull(unit, "unit");
            return(unit.Between(this, end));
        }
Beispiel #23
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());
            }
        }
Beispiel #24
0
        public static Value TemporalValue(Temporal value)
        {
            if (value is ZonedDateTime)
            {
                return(datetime(( ZonedDateTime )value));
            }
            if (value is OffsetDateTime)
            {
                return(datetime(( OffsetDateTime )value));
            }
            if (value is DateTime)
            {
                return(localDateTime(( DateTime )value));
            }
            if (value is OffsetTime)
            {
                return(time(( OffsetTime )value));
            }
            if (value is LocalDate)
            {
                return(date(( LocalDate )value));
            }
            if (value is LocalTime)
            {
                return(localTime(( LocalTime )value));
            }
            if (value is TemporalValue)
            {
                return(( Value )value);
            }
            if (value == null)
            {
                return(NoValue);
            }

            throw new System.NotSupportedException("Unsupported type of Temporal " + value.ToString());
        }
Beispiel #25
0
        private static DurationValue DurationInSecondsAndNanos(Temporal from, Temporal to)
        {
            long seconds;
            long nanos;
            bool negate = false;

            if (from.isSupported(OFFSET_SECONDS) && !to.isSupported(OFFSET_SECONDS))
            {
                negate = true;
                Temporal tmp = from;
                from = to;
                to   = tmp;
            }
            seconds = AssertValidUntil(from, to, SECONDS);
            int fromNanos = from.isSupported(NANO_OF_SECOND) ? from.get(NANO_OF_SECOND) : 0;
            int toNanos   = to.isSupported(NANO_OF_SECOND) ? to.get(NANO_OF_SECOND) : 0;

            nanos = toNanos - fromNanos;

            bool differenceIsLessThanOneSecond = seconds == 0 && from.isSupported(SECOND_OF_MINUTE) && to.isSupported(SECOND_OF_MINUTE) && from.get(SECOND_OF_MINUTE) != to.get(SECOND_OF_MINUTE);

            if (nanos < 0 && (seconds > 0 || differenceIsLessThanOneSecond))
            {
                nanos = NANOS_PER_SECOND + nanos;
            }
            else if (nanos > 0 && (seconds < 0 || differenceIsLessThanOneSecond))
            {
                nanos = nanos - NANOS_PER_SECOND;
            }
            if (negate)
            {
                seconds = -seconds;
                nanos   = -nanos;
            }
            return(Duration(0, 0, seconds, nanos));
        }
Beispiel #26
0
 /// <summary>
 /// Adjusts the specified temporal object to have the same offset as this object.
 /// <para>
 /// This returns a temporal object of the same observable type as the input
 /// with the offset changed to be the same as this.
 /// </para>
 /// <para>
 /// The adjustment is equivalent to using <seealso cref="Temporal#with(TemporalField, long)"/>
 /// passing <seealso cref="ChronoField#OFFSET_SECONDS"/> as the field.
 /// </para>
 /// <para>
 /// In most cases, it is clearer to reverse the calling pattern by using
 /// <seealso cref="Temporal#with(TemporalAdjuster)"/>:
 /// <pre>
 ///   // these two lines are equivalent, but the second approach is recommended
 ///   temporal = thisOffset.adjustInto(temporal);
 ///   temporal = temporal.with(thisOffset);
 /// </pre>
 /// </para>
 /// <para>
 /// This instance is immutable and unaffected by this method call.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the target object to be adjusted, not null </param>
 /// <returns> the adjusted object, not null </returns>
 /// <exception cref="DateTimeException"> if unable to make the adjustment </exception>
 /// <exception cref="ArithmeticException"> if numeric overflow occurs </exception>
 public Temporal AdjustInto(Temporal temporal)
 {
     return(temporal.With(OFFSET_SECONDS, TotalSeconds_Renamed));
 }
Beispiel #27
0
 public static ValueRepresentation Temporal(Temporal value)
 {
     return(new ValueRepresentation(RepresentationType.Temporal, value.ToString()));
 }
Beispiel #28
0
 protected internal override Representation dispatchTemporalProperty(Temporal temporal, Void param)
 {
     return(new ValueRepresentation(RepresentationType.Temporal, temporal));
 }
Beispiel #29
0
        public HttpResponseMessage PrerenderPages() // /umbraco/api/carbidesupport/prerenderpages/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Pre-rendering templates... ";
                        timer2.Reset();
                        timer2.Start();

                        var umbracoHelper    = new UmbracoHelper(Carbide.ContextHelpers.EnsureUmbracoContext());
                        int pageCounter      = 0;
                        List <int> templates = new List <int>();

                        foreach (var node in umbracoHelper.TypedContentAtRoot())
                        {
                            ListChildNodes(node, ref pageCounter, ref context, ref templates);
                        }

                        if (pageCounter > 1)
                        {
                            var msg = context.Application["RebuildCacheHistory"].ToString();
                            msg     = msg.Substring(0, msg.LastIndexOf("..."));
                            context.Application["RebuildCacheHistory"] = msg + "... ";
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>" + pageCounter + " template" + (pageCounter != 1 ? "s" : "") + " in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }
Beispiel #30
0
        public HttpResponseMessage RebuildImageCache() // /umbraco/api/carbidesupport/rebuildimagecache/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Clearing cached images... ";
                        timer2.Start();

                        foreach (var folder in Storage.GetFolders("/App_Data/cache/"))
                        {
                            Storage.DeleteDirectory("/App_Data/cache/" + folder);

                            if (Storage.DirectoryExists("/App_Data/cache/" + folder))
                            {
                                // Retry up to 5 times after pausing...

                                int retry = 0;

                                string original = context.Application["RebuildCacheHistory"].ToString();

                                while (retry < 5)
                                {
                                    retry++;

                                    context.Application["RebuildCacheHistory"] = original + "cache/" + folder + " retry " + retry;

                                    Temporal.PauseExecution(1);

                                    if (Storage.DirectoryExists("/App_Data/cache/" + folder))
                                    {
                                        Storage.DeleteDirectory("/App_Data/cache/" + folder);
                                    }

                                    if (!Storage.DirectoryExists("/App_Data/cache/" + folder))
                                    {
                                        retry = 5;
                                    }
                                }

                                context.Application["RebuildCacheHistory"] = original;

                                if (Storage.DirectoryExists("/App_Data/cache/" + folder))
                                {
                                    context.Application["RebuildCacheHistory"] += "<strong style='color:#b94a48;'>cache/" + folder + " locked...</strong> ";
                                }
                            }
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }
Beispiel #31
0
        public HttpResponseMessage RebuildCache() // /umbraco/api/carbidesupport/rebuildcache/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Republishing all content... ";
                        timer2.Reset();
                        timer2.Start();
                        Services.ContentService.RePublishAll();
                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Refreshing XML cache... ";
                        timer2.Reset();
                        timer2.Start();
                        umbraco.library.RefreshContent();
                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Rebuilding Examine indexes... ";
                        timer2.Reset();
                        timer2.Start();

                        foreach (var index in ExamineManager.Instance.IndexProviderCollection.ToList())
                        {
                            context.Application["RebuildCacheHistory"] += index.Name.Replace("Indexer", "") + "... ";
                            index.RebuildIndex();
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + Temporal.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + Temporal.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }