Ejemplo n.º 1
0
 public override bool Equals(Value other)
 {
     if (other is DateTimeValue)
     {
         ZonedDateTime that = (( DateTimeValue )other)._value;
         bool          res  = _value.toLocalDateTime().Equals(that.toLocalDateTime());
         if (res)
         {
             ZoneId thisZone     = _value.Zone;
             ZoneId thatZone     = that.Zone;
             bool   thisIsOffset = thisZone is ZoneOffset;
             bool   thatIsOffset = thatZone is ZoneOffset;
             if (thisIsOffset && thatIsOffset)
             {
                 res = thisZone.Equals(thatZone);
             }
             else if (!thisIsOffset && !thatIsOffset)
             {
                 res = string.ReferenceEquals(TimeZones.map(thisZone.Id), TimeZones.map(thatZone.Id));
             }
             else
             {
                 res = false;
             }
         }
         return(res);
     }
     return(false);
 }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------
        private void ResolveFields()
        {
            // resolve ChronoField
            ResolveInstantFields();
            ResolveDateFields();
            ResolveTimeFields();

            // if any other fields, handle them
            // any lenient date resolution should return epoch-day
            if (FieldValues.Count > 0)
            {
                int changedCount = 0;
                while (changedCount < 50)
                {
                    foreach (Map_Entry <TemporalField, Long> entry in FieldValues)
                    {
                        TemporalField    targetField    = entry.Key;
                        TemporalAccessor resolvedObject = targetField.resolve(FieldValues, this, ResolverStyle);
                        if (resolvedObject != java.time.temporal.TemporalAccessor_Fields.Null)
                        {
                            if (resolvedObject is ChronoZonedDateTime)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.time.chrono.ChronoZonedDateTime<?> czdt = (java.time.chrono.ChronoZonedDateTime<?>) resolvedObject;
                                ChronoZonedDateTime <?> czdt = (ChronoZonedDateTime <?>)resolvedObject;
                                if (Zone == java.time.temporal.TemporalAccessor_Fields.Null)
                                {
                                    Zone = czdt.Zone;
                                }
                                else if (Zone.Equals(czdt.Zone) == false)
                                {
                                    throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + Zone);
                                }
                                resolvedObject = czdt.ToLocalDateTime();
                            }
                            if (resolvedObject is ChronoLocalDateTime)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.time.chrono.ChronoLocalDateTime<?> cldt = (java.time.chrono.ChronoLocalDateTime<?>) resolvedObject;
                                ChronoLocalDateTime <?> cldt = (ChronoLocalDateTime <?>)resolvedObject;
                                UpdateCheckConflict(cldt.ToLocalTime(), Period.ZERO);
                                UpdateCheckConflict(cldt.ToLocalDate());
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            if (resolvedObject is ChronoLocalDate)
                            {
                                UpdateCheckConflict((ChronoLocalDate)resolvedObject);
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            if (resolvedObject is LocalTime)
                            {
                                UpdateCheckConflict((LocalTime)resolvedObject, Period.ZERO);
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " + "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
                        }
                        else if (FieldValues.ContainsKey(targetField) == false)
                        {
                            changedCount++;
                            goto outerContinue;                             // have to restart to avoid concurrent modification
                        }
                    }
                    break;
                    outerContinue :;
                }
                outerBreak :
                if (changedCount == 50)                 // catch infinite loops
                {
                    throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
                }
                // if something changed then have to redo ChronoField resolve
                if (changedCount > 0)
                {
                    ResolveInstantFields();
                    ResolveDateFields();
                    ResolveTimeFields();
                }
            }
        }
Ejemplo n.º 3
0
        public virtual void test_swapIndicies()
        {
            ImmutableMap <string, SwapIndex> mapAll   = SwapIndices.ENUM_LOOKUP.lookupAll();
            ImmutableList <SwapIndex>        indexAll = mapAll.values().asList();
            ImmutableList <string>           nameAll  = mapAll.Keys.asList();
            int size = indexAll.size();

            for (int i = 0; i < size; ++i)
            {
                // check no duplication
                for (int j = i + 1; j < size; ++j)
                {
                    assertFalse(nameAll.get(i).Equals(nameAll.get(j)));
                    assertFalse(indexAll.get(i).Equals(indexAll.get(j)));
                }
            }
            foreach (string name in nameAll)
            {
                SwapIndex index = mapAll.get(name);
                assertEquals(SwapIndex.of(name), index);
                assertEquals(index.Active, true);
                FixedIborSwapTemplate   temp = index.Template;
                FixedIborSwapConvention conv = temp.Convention;
                Tenor     tenor = temp.Tenor;
                LocalTime time  = index.FixingTime;
                ZoneId    zone  = index.FixingZone;
                // test consistency between name and template
                assertTrue(name.Contains(tenor.ToString()));
                if (name.StartsWith("USD", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1500"));
                    assertTrue(conv.Equals(FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M));
                    assertTrue(zone.Equals(NEY_YORK));
                }
                if (name.StartsWith("GBP", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_1Y_LIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_6M_LIBOR_6M));
                    }
                    assertTrue(zone.Equals(LONDON));
                }
                if (name.StartsWith("EUR", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1200"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_6M));
                    }
                    assertTrue(zone.Equals(FRANKFURT));
                }
                if (name.Contains("1100"))
                {
                    assertTrue(time.Equals(LocalTime.of(11, 0)));
                }
                if (name.Contains("1200"))
                {
                    assertTrue(time.Equals(LocalTime.of(12, 0)));
                }
                if (name.Contains("1500"))
                {
                    assertTrue(time.Equals(LocalTime.of(15, 0)));
                }
                assertEquals(index.calculateFixingDateTime(date(2015, 6, 30)), date(2015, 6, 30).atTime(time).atZone(zone));
            }
        }