Example #1
0
        public static LocalDateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "local date time");

            LocalDate truncatedDate = pair.First();
            LocalTime truncatedTime = pair.Other();

            DateTime truncatedLDT = new DateTime(truncatedDate, truncatedTime);

            if (fields.Size() == 0)
            {
                return(LocalDateTime(truncatedLDT));
            }
            else
            {
                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedLDT, (mapValue, localDateTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return LocalDateTime(LocalDateTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("datetime", LocalDateTime(LocalDateTime)), defaultZone);
                    }
                }));
            }
        }
Example #2
0
        public static TimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            OffsetTime time        = input.getTimePart(defaultZone);
            OffsetTime truncatedOT = AssertValidUnit(() => time.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(time(truncatedOT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    ZonedDateTime currentDT     = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), TimezoneOf(timezone)));
                    ZoneOffset    currentOffset = currentDT.Offset;
                    truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return time(offsetTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
                    }
                }));
            }
        }
Example #3
0
            protected internal override Header.Entry Entry <T1>(int index, string name, string typeSpec, Group group, Extractors extractors, Extractor <T1> idExtractor)
            {
                Type type = null;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.csv.reader.Extractor<?> extractor = null;
                Extractor <object>   extractor         = null;
                CSVHeaderInformation optionalParameter = null;

                if (string.ReferenceEquals(typeSpec, null))
                {                         // Property
                    type      = Type.Property;
                    extractor = extractors.String();
                }
                else
                {
                    Pair <string, string> split = SplitTypeSpecAndOptionalParameter(typeSpec);
                    typeSpec = split.First();
                    string optionalParameterString = split.Other();
                    if (!string.ReferenceEquals(optionalParameterString, null))
                    {
                        if (Extractors.PointExtractor.NAME.Equals(typeSpec))
                        {
                            optionalParameter = PointValue.parseHeaderInformation(optionalParameterString);
                        }
                        else if (Extractors.TimeExtractor.NAME.Equals(typeSpec) || Extractors.DateTimeExtractor.NAME.Equals(typeSpec))
                        {
                            optionalParameter = TemporalValue.parseHeaderInformation(optionalParameterString);
                        }
                    }

                    if (typeSpec.Equals(Type.StartId.name(), StringComparison.OrdinalIgnoreCase))
                    {
                        type      = Type.StartId;
                        extractor = idExtractor;
                    }
                    else if (typeSpec.Equals(Type.EndId.name(), StringComparison.OrdinalIgnoreCase))
                    {
                        type      = Type.EndId;
                        extractor = idExtractor;
                    }
                    else if (typeSpec.Equals(Type.Type.name(), StringComparison.OrdinalIgnoreCase))
                    {
                        type      = Type.Type;
                        extractor = extractors.String();
                    }
                    else if (IsRecognizedType(typeSpec))
                    {
                        throw new HeaderException("Unexpected relationship header type '" + typeSpec + "'");
                    }
                    else
                    {
                        type      = Type.Property;
                        extractor = ParsePropertyType(typeSpec, extractors);
                    }
                }
                return(new Header.Entry(name, type, group, extractor, optionalParameter));
            }
Example #4
0
 private LocalDate getDateOf(Org.Neo4j.Values.AnyValue temporal)
 {
     if (temporal is TemporalValue)
     {
         TemporalValue v = ( TemporalValue )temporal;
         return(v.DatePart);
     }
     throw new InvalidValuesArgumentException(string.Format("Cannot construct date from: {0}", temporal));
 }
Example #5
0
 private DateTime getLocalDateTimeOf(AnyValue temporal)
 {
     if (temporal is TemporalValue)
     {
         TemporalValue v        = ( TemporalValue )temporal;
         LocalDate     datePart = v.DatePart;
         LocalTime     timePart = v.LocalTimePart;
         return(new DateTime(datePart, timePart));
     }
     throw new InvalidValuesArgumentException(string.Format("Cannot construct date from: {0}", temporal));
 }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParseTimeThatOverridesHeaderInformation()
        internal virtual void ShouldBeAbleToParseTimeThatOverridesHeaderInformation()
        {
            string headerInformation = "{timezone:-01:00}";
            string data = "14:05:17Z";

            TimeValue expected = TimeValue.Parse(data, OrFail);
            TimeValue actual   = TimeValue.Parse(data, OrFail, TemporalValue.ParseHeaderInformation(headerInformation));

            assertEqual(expected, actual);
            assertEquals(UTC, actual.ZoneOffset);
        }
Example #7
0
            protected internal override LocalTimeValue selectTime(AnyValue time)
            {
                if (!(time is TemporalValue))
                {
                    throw new InvalidValuesArgumentException(string.Format("Cannot construct local time from: {0}", time));
                }
                TemporalValue v  = ( TemporalValue )time;
                LocalTime     lt = v.LocalTimePart;

                return(LocalTime(lt));
            }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToParseTimeWithoutTimeZoneWithHeaderInformation()
        internal virtual void ShouldBeAbleToParseTimeWithoutTimeZoneWithHeaderInformation()
        {
            string headerInformation = "{timezone:-01:00}";
            string data = "14:05:17";

            TimeValue expected   = TimeValue.Parse(data, () => ZoneId.of("-01:00"));
            TimeValue unexpected = TimeValue.Parse(data, InUTC);
            TimeValue actual     = TimeValue.Parse(data, OrFail, TemporalValue.ParseHeaderInformation(headerInformation));

            assertEqual(expected, actual);
            assertNotEquals(unexpected, actual);
        }
Example #9
0
        public static DateValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            LocalDate localDate = input.DatePart;
            DateValue truncated = Date(TruncateTo(localDate, unit));

            if (fields.Size() == 0)
            {
                return(truncated);
            }
            else
            {
                MapValue updatedFields = fields.UpdatedWith("date", truncated);
                return(Build(updatedFields, defaultZone));
            }
        }
Example #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.values.AnyValue apply(org.neo4j.kernel.api.proc.Context ctx, org.neo4j.values.AnyValue[] input) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
            public override AnyValue Apply(Context ctx, AnyValue[] input)
            {
                if (input == null || (input.Length == 2 && (input[0] == NO_VALUE || input[0] == null) || input[1] == NO_VALUE || input[1] == null))
                {
                    return(NO_VALUE);
                }
                else if (input.Length == 2)
                {
                    if (input[0] is TemporalValue && input[1] is TemporalValue)
                    {
                        TemporalValue from = ( TemporalValue )input[0];
                        TemporalValue to   = ( TemporalValue )input[1];
                        return(DurationValue.between(Unit, from, to));
                    }
                }
                throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureCallFailed, "Invalid call signature for " + this.GetType().Name + ": Provided input was " + Arrays.ToString(input));
            }
Example #11
0
            public override TimeValue buildInternal()
            {
                bool       selectingTime = fields.containsKey(TemporalFields.Time);
                bool       selectingTimeZone;
                OffsetTime result;

                if (selectingTime)
                {
                    AnyValue time = fields.get(TemporalFields.Time);
                    if (!(time is TemporalValue))
                    {
                        throw new InvalidValuesArgumentException(string.Format("Cannot construct time from: {0}", time));
                    }
                    TemporalValue t = ( TemporalValue )time;
                    result            = t.getTimePart(_defaultZone);
                    selectingTimeZone = t.supportsTimeZone();
                }
                else
                {
                    ZoneId timezone = timezone();
                    if (!(timezone is ZoneOffset))
                    {
                        timezone = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), timezone())).Offset;
                    }

                    result            = DefaultTime(timezone);
                    selectingTimeZone = false;
                }

                result = assignAllFields(result);
                if (timezone != null)
                {
                    ZoneOffset currentOffset = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), timezone())).Offset;
                    if (selectingTime && selectingTimeZone)
                    {
                        result = result.withOffsetSameInstant(currentOffset);
                    }
                    else
                    {
                        result = result.withOffsetSameLocal(currentOffset);
                    }
                }
                return(Time(result));
            }
Example #12
0
        public Point[] ConvertTemporalValues(TemporalValue <double>[] points)
        {
            List <Point> result = new List <Point>();

            float fWidth  = x_max - x_min;
            float fHeight = y_max - y_min;

            for (int i = 0; i < points.Length; i++)
            {
                TemporalValue <double> v = points[i];
                if (v.TimeStamp >= x_min && x_max >= v.TimeStamp && v.Value >= y_min && y_max >= v.Value)
                {
                    int x = m_drect.X + (int)((v.TimeStamp - x_min) * m_drect.Width / fWidth);
                    int y = m_drect.Y + (int)((y_max - v.Value) * m_drect.Height / fHeight);
                    result.Add(new Point(x, y));
                }
            }
            return(result.ToArray());
        }
Example #13
0
            protected internal override TimeValue selectTime(AnyValue temporal)
            {
                if (!(temporal is TemporalValue))
                {
                    throw new InvalidValuesArgumentException(string.Format("Cannot construct time from: {0}", temporal));
                }
                if (temporal is TimeValue && timezone == null)
                {
                    return(( TimeValue )temporal);
                }

                TemporalValue v    = ( TemporalValue )temporal;
                OffsetTime    time = v.getTimePart(_defaultZone);

                if (timezone != null)
                {
                    ZoneOffset currentOffset = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), timezone())).Offset;
                    time = time.withOffsetSameInstant(currentOffset);
                }
                return(time(time));
            }
Example #14
0
        public static LocalTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            LocalTime localTime   = input.LocalTimePart;
            LocalTime truncatedLT = AssertValidUnit(() => localTime.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(localTime(truncatedLT));
            }
            else
            {
                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedLT, (mapValue, localTime1) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return localTime(localTime1);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", localTime(localTime1)), defaultZone);
                    }
                }));
            }
        }
Example #15
0
        public static DateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "date time");

            LocalDate truncatedDate = pair.First();
            LocalTime truncatedTime = pair.Other();

            ZoneId        zoneId       = input.supportsTimeZone() ? input.getZoneId(defaultZone) : defaultZone();
            ZonedDateTime truncatedZDT = ZonedDateTime.of(truncatedDate, truncatedTime, zoneId);

            if (fields.Size() == 0)
            {
                return(Datetime(truncatedZDT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    truncatedZDT = truncatedZDT.withZoneSameLocal(TimezoneOf(timezone));
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedZDT, (mapValue, zonedDateTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return Datetime(zonedDateTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("datetime", Datetime(zonedDateTime)), defaultZone);
                    }
                }));
            }
        }
Example #16
0
 protected internal override LocalTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
 {
     return(LocalTimeValue.truncate(unit, input, fields, defaultZone));
 }
Example #17
0
            public override LocalDateTimeValue buildInternal()
            {
                bool     selectingDate     = fields.containsKey(TemporalFields.Date);
                bool     selectingTime     = fields.containsKey(TemporalFields.Time);
                bool     selectingDateTime = fields.containsKey(TemporalFields.Datetime);
                DateTime result;

                if (selectingDateTime)
                {
                    AnyValue dtField = fields.get(TemporalFields.Datetime);
                    if (!(dtField is TemporalValue))
                    {
                        throw new InvalidValuesArgumentException(string.Format("Cannot construct local date time from: {0}", dtField));
                    }
                    TemporalValue dt = ( TemporalValue )dtField;
                    result = new DateTime(dt.DatePart, dt.LocalTimePart);
                }
                else if (selectingTime || selectingDate)
                {
                    LocalTime time;
                    if (selectingTime)
                    {
                        AnyValue timeField = fields.get(TemporalFields.Time);
                        if (!(timeField is TemporalValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct local time from: {0}", timeField));
                        }
                        TemporalValue t = ( TemporalValue )timeField;
                        time = t.LocalTimePart;
                    }
                    else
                    {
                        time = LocalTimeValue.DefaultLocalTime;
                    }
                    LocalDate date;
                    if (selectingDate)
                    {
                        AnyValue dateField = fields.get(TemporalFields.Date);
                        if (!(dateField is TemporalValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct date from: {0}", dateField));
                        }
                        TemporalValue t = ( TemporalValue )dateField;
                        date = t.DatePart;
                    }
                    else
                    {
                        date = DateValue.DefaultCalenderDate;
                    }

                    result = new DateTime(date, time);
                }
                else
                {
                    result = DefaultLocalDateTime;
                }

                if (fields.containsKey(TemporalFields.Week) && !selectingDate && !selectingDateTime)
                {
                    // Be sure to be in the start of the week based year (which can be later than 1st Jan)
                    result = result.with(IsoFields.WEEK_BASED_YEAR, safeCastIntegral(TemporalFields.Year.name(), fields.get(TemporalFields.Year), TemporalFields.Year.defaultValue)).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1);
                }

                result = assignAllFields(result);
                return(LocalDateTime(result));
            }
Example #18
0
 public static DurationValue Parse(TextValue text)
 {
     return(TemporalValue.Parse(typeof(DurationValue), _pattern, DurationValue.parse, text));
 }
Example #19
0
            public override DateTimeValue buildInternal()
            {
                bool          selectingDate     = fields.containsKey(TemporalFields.Date);
                bool          selectingTime     = fields.containsKey(TemporalFields.Time);
                bool          selectingDateTime = fields.containsKey(TemporalFields.Datetime);
                bool          selectingEpoch    = fields.containsKey(TemporalFields.EpochSeconds) || fields.containsKey(TemporalFields.EpochMillis);
                bool          selectingTimeZone;
                ZonedDateTime result;

                if (selectingDateTime)
                {
                    AnyValue dtField = fields.get(TemporalFields.Datetime);
                    if (!(dtField is TemporalValue))
                    {
                        throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", dtField));
                    }
                    TemporalValue dt       = ( TemporalValue )dtField;
                    LocalTime     timePart = dt.getTimePart(_defaultZone).toLocalTime();
                    ZoneId        zoneId   = dt.getZoneId(_defaultZone);
                    result            = ZonedDateTime.of(dt.DatePart, timePart, zoneId);
                    selectingTimeZone = dt.supportsTimeZone();
                }
                else if (selectingEpoch)
                {
                    if (fields.containsKey(TemporalFields.EpochSeconds))
                    {
                        AnyValue epochField = fields.get(TemporalFields.EpochSeconds);
                        if (!(epochField is IntegralValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", epochField));
                        }
                        IntegralValue epochSeconds = ( IntegralValue )epochField;
                        result = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochSeconds.LongValue() * 1000), timezone()));
                    }
                    else
                    {
                        AnyValue epochField = fields.get(TemporalFields.EpochMillis);
                        if (!(epochField is IntegralValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", epochField));
                        }
                        IntegralValue epochMillis = ( IntegralValue )epochField;
                        result = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMillis.LongValue()), timezone()));
                    }
                    selectingTimeZone = false;
                }
                else if (selectingTime || selectingDate)
                {
                    LocalTime time;
                    ZoneId    zoneId;
                    if (selectingTime)
                    {
                        AnyValue timeField = fields.get(TemporalFields.Time);
                        if (!(timeField is TemporalValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct time from: {0}", timeField));
                        }
                        TemporalValue t = ( TemporalValue )timeField;
                        time              = t.getTimePart(_defaultZone).toLocalTime();
                        zoneId            = t.getZoneId(_defaultZone);
                        selectingTimeZone = t.supportsTimeZone();
                    }
                    else
                    {
                        time              = LocalTimeValue.DefaultLocalTime;
                        zoneId            = timezone();
                        selectingTimeZone = false;
                    }
                    LocalDate date;
                    if (selectingDate)
                    {
                        AnyValue dateField = fields.get(TemporalFields.Date);
                        if (!(dateField is TemporalValue))
                        {
                            throw new InvalidValuesArgumentException(string.Format("Cannot construct date from: {0}", dateField));
                        }
                        TemporalValue t = ( TemporalValue )dateField;
                        date = t.DatePart;
                    }
                    else
                    {
                        date = DateValue.DefaultCalenderDate;
                    }
                    result = ZonedDateTime.of(date, time, zoneId);
                }
                else
                {
                    result            = defaultZonedDateTime;
                    selectingTimeZone = false;
                }

                if (fields.containsKey(TemporalFields.Week) && !selectingDate && !selectingDateTime && !selectingEpoch)
                {
                    // Be sure to be in the start of the week based year (which can be later than 1st Jan)
                    result = result.with(IsoFields.WEEK_BASED_YEAR, safeCastIntegral(TemporalFields.Year.name(), fields.get(TemporalFields.Year), TemporalFields.Year.defaultValue)).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1);
                }

                result = assignAllFields(result);
                if (timezone != null)
                {
                    if (((selectingTime || selectingDateTime) && selectingTimeZone) || selectingEpoch)
                    {
                        try
                        {
                            result = result.withZoneSameInstant(timezone());
                        }
                        catch (DateTimeParseException e)
                        {
                            throw new InvalidValuesArgumentException(e.Message, e);
                        }
                    }
                    else
                    {
                        result = result.withZoneSameLocal(timezone());
                    }
                }
                return(Datetime(result));
            }