Exemplo n.º 1
0
        protected virtual DateTimeInterval BuildClassic(string value)
        {
            if (!(value.StartsWith("]") || value.StartsWith("[")))
            {
                ex = new ArgumentException("The interval definition must start by '[' or ']'");
            }
            if (!(value.EndsWith("]") || value.EndsWith("[")))
            {
                ex = new ArgumentException("The interval definition must end by '[' or ']'");
            }
            if (!(value.Contains(";")))
            {
                ex = new ArgumentException("The interval definition must contain a delimitor ';'");
            }

            var split = value.Split(';');

            if (split.Count() > 2)
            {
                ex = new ArgumentException("The interval definition must contain only one delimitor ';'");
            }

            if (ex != null)
            {
                return(null);
            }

            EndPoint <DateTime> left, right;

            if (split[0].StartsWith("["))
            {
                left = new LeftEndPointClosed <DateTime>(
                    DateTime.Parse(split[0].Substring(1, split[0].Length - 1), CultureInfo.InvariantCulture.DateTimeFormat));
            }
            else
            {
                left = new LeftEndPointOpen <DateTime>(
                    DateTime.Parse(split[0].Substring(1, split[0].Length - 1), CultureInfo.InvariantCulture.DateTimeFormat));
            }

            if (split[1].EndsWith("]"))
            {
                right = new RightEndPointClosed <DateTime>(
                    DateTime.Parse(split[1].Substring(0, split[1].Length - 1), CultureInfo.InvariantCulture.DateTimeFormat));
            }
            else
            {
                right = new RightEndPointOpen <DateTime>(
                    DateTime.Parse(split[1].Substring(0, split[1].Length - 1), CultureInfo.InvariantCulture.DateTimeFormat));
            }

            return(new DateTimeInterval(left, right));
        }
Exemplo n.º 2
0
        protected virtual NumericInterval BuildClassic(string value)
        {
            if (!(value.StartsWith("]") || value.StartsWith("[")))
            {
                ex = new ArgumentException("The interval definition must start by '[' or ']'");
            }
            if (!(value.EndsWith("]") || value.EndsWith("[")))
            {
                ex = new ArgumentException("The interval definition must end by '[' or ']'");
            }
            if (!(value.Contains(";")))
            {
                ex = new ArgumentException("The interval definition must contain a delimitor ';'");
            }

            var split = value.Split(';');

            if (split.Count() > 2)
            {
                ex = new ArgumentException("The interval definition must contain only one delimitor ';'");
            }

            if (ex != null)
            {
                return(null);
            }

            EndPoint <double> left, right;

            if (split[0].Substring(1, split[0].Length - 1).ToLower() == "-inf")
            {
                left = new LeftEndPointNegativeInfinity();
            }
            else
            if (split[0].StartsWith("["))
            {
                left = new LeftEndPointClosed <double>(
                    Double.Parse(split[0].Substring(1, split[0].Length - 1), CultureInfo.InvariantCulture.NumberFormat));
            }
            else
            {
                left = new LeftEndPointOpen <double>(
                    Double.Parse(split[0].Substring(1, split[0].Length - 1), CultureInfo.InvariantCulture.NumberFormat));
            }

            if (split[1].Substring(0, split[1].Length - 1).ToLower() == "+inf" ||
                split[1].Substring(0, split[1].Length - 1).ToLower() == "inf")
            {
                right = new RightEndPointPositiveInfinity();
            }
            else
            if (split[1].EndsWith("]"))
            {
                right = new RightEndPointClosed <double>(
                    Double.Parse(split[1].Substring(0, split[1].Length - 1), CultureInfo.InvariantCulture.NumberFormat));
            }
            else
            {
                right = new RightEndPointOpen <double>(
                    Double.Parse(split[1].Substring(0, split[1].Length - 1), CultureInfo.InvariantCulture.NumberFormat));
            }

            return(new NumericInterval(left, right));
        }