Exemplo n.º 1
0
        public static IExtendedDateTimeIndependentType Parse(string EDTFtedString)
        {
            if (string.IsNullOrEmpty(EDTFtedString))
            {
                throw new ParseException("The input string cannot be empty.", EDTFtedString);
            }

            if (EDTFtedString.Contains('/'))
            {
                return(ExtendedDateTimeIntervalParser.Parse(EDTFtedString));
            }

            if (EDTFtedString[0] == '{')
            {
                return(ExtendedDateTimeCollectionParser.Parse(EDTFtedString));
            }
            else if (EDTFtedString[0] == '[')
            {
                return(ExtendedDateTimePossibilityCollectionParser.Parse(EDTFtedString));
            }
            else if (EDTFtedString.ContainsBefore('u', '^'))
            {
                return(UnspecifiedExtendedDateTimeParser.Parse(EDTFtedString));
            }
            else if (EDTFtedString.ContainsBefore('x', '^'))
            {
                return(ExtendedDateTimeMaskedPrecisionParser.Parse(EDTFtedString));
            }
            else
            {
                return(ExtendedDateTimeParser.Parse(EDTFtedString));
            }
        }
Exemplo n.º 2
0
        internal static ExtendedDateTime Parse(string extendedDateTimeString, ExtendedDateTime container)
        {
            if (string.IsNullOrWhiteSpace(extendedDateTimeString))
            {
                return(new ExtendedDateTime());
            }

            return(ExtendedDateTimeParser.Parse(extendedDateTimeString, container));
        }
Exemplo n.º 3
0
        public static ExtendedDateTime Parse(string extendedDateTimeString)
        {
            if (string.IsNullOrWhiteSpace(extendedDateTimeString))
            {
                return(new ExtendedDateTime());
            }

            return(ExtendedDateTimeParser.Parse(extendedDateTimeString));
        }
        internal static ExtendedDateTimeRange Parse(string extendedDateTimeRangeString, ExtendedDateTimeRange extendedDateTimeRange = null)
        {
            if (string.IsNullOrWhiteSpace(extendedDateTimeRangeString))
            {
                return(null);
            }

            var rangeParts = extendedDateTimeRangeString.Split(new string[] { ".." }, StringSplitOptions.None);   // An empty entry indicates a range with only one defined side.

            if (rangeParts.Length != 2)
            {
                throw new ParseException("A range string must have exactly one \"..\".", extendedDateTimeRangeString);
            }

            if (extendedDateTimeRange == null)
            {
                extendedDateTimeRange = new ExtendedDateTimeRange();
            }

            var startString = rangeParts[0];
            var endString   = rangeParts[1];

            if (string.IsNullOrEmpty(rangeParts[0]))
            {
                extendedDateTimeRange.Start = ExtendedDateTime.Minimum;
            }
            else
            {
                extendedDateTimeRange.Start = ExtendedDateTimeParser.Parse(startString);
            }

            if (string.IsNullOrEmpty(rangeParts[1]))
            {
                extendedDateTimeRange.End = ExtendedDateTime.Maximum;
            }
            else
            {
                extendedDateTimeRange.End = ExtendedDateTimeParser.Parse(endString);
            }

            return(extendedDateTimeRange);
        }
Exemplo n.º 5
0
        internal static ExtendedDateTimeInterval Parse(string extendedDateTimeIntervalString, ExtendedDateTimeInterval extendedDateTimeInterval = null)
        {
            if (string.IsNullOrWhiteSpace(extendedDateTimeIntervalString))
            {
                return(null);
            }

            var intervalPartStrings = extendedDateTimeIntervalString.Split(new char[] { '/' });

            if (intervalPartStrings.Length != 2)
            {
                throw new ParseException("An interval string must contain exactly one forward slash.", extendedDateTimeIntervalString);
            }

            var startString = intervalPartStrings[0];
            var endString   = intervalPartStrings[1];

            if (extendedDateTimeInterval == null)
            {
                extendedDateTimeInterval = new ExtendedDateTimeInterval();
            }

            if (startString[0] == '{')
            {
                throw new ParseException("An interval cannot contain a collection.", startString);
            }

            if (startString == "unknown")
            {
                extendedDateTimeInterval.Start = ExtendedDateTime.Unknown;
            }
            else if (startString == "open")
            {
                extendedDateTimeInterval.Start = ExtendedDateTime.Open;
            }
            else if (startString[0] == '[')
            {
                extendedDateTimeInterval.Start = ExtendedDateTimePossibilityCollectionParser.Parse(startString);
            }
            else if (startString.ContainsBefore('u', '^'))
            {
                extendedDateTimeInterval.Start = UnspecifiedExtendedDateTimeParser.Parse(startString);
            }
            else
            {
                extendedDateTimeInterval.Start = ExtendedDateTimeParser.Parse(startString);
            }

            if (endString[0] == '{')
            {
                throw new ParseException("An interval cannot contain a collection.", startString);
            }

            if (endString == "unknown")
            {
                extendedDateTimeInterval.End = ExtendedDateTime.Unknown;
            }
            else if (endString == "open")
            {
                extendedDateTimeInterval.End = ExtendedDateTime.Open;
            }
            else if (endString[0] == '[')
            {
                extendedDateTimeInterval.End = ExtendedDateTimePossibilityCollectionParser.Parse(endString);
            }
            else if (endString.ContainsBefore('u', '^'))
            {
                extendedDateTimeInterval.End = UnspecifiedExtendedDateTimeParser.Parse(endString);
            }
            else
            {
                extendedDateTimeInterval.End = ExtendedDateTimeParser.Parse(endString);
            }

            return(extendedDateTimeInterval);
        }