예제 #1
0
        private LiteralExpression ParseDateLiteral()
        {
            string      text       = _token.Text;
            SourceRange tokenRange = _token.Range;

            NextToken();

            DateTime value;

            if (text.Length < 3 || text[0] != '#' || text[text.Length - 1] != '#')
            {
                _errorReporter.InvalidDate(tokenRange, text);
                value = DateTime.MinValue;
            }
            else
            {
                string textWithoutDelimiters = text.Substring(1, text.Length - 2);
                try
                {
                    value = DateTime.Parse(textWithoutDelimiters, CultureInfo.InvariantCulture);
                }
                catch (FormatException)
                {
                    _errorReporter.InvalidDate(tokenRange, textWithoutDelimiters);
                    value = DateTime.MinValue;
                }
            }

            return(LiteralExpression.FromDateTime(value));
        }