예제 #1
0
 private void SetResult(Memezo.Value value)
 {
     this.Result =
         DateTimeUtility.TryParseDateTime(value.String, out var dateTime) ? $"'{DateTimeUtility.DateTimeToString(dateTime)}'" :
         DateTimeUtility.TryParseTimeSpan(value.String, out var timeSpan) ? $"'{DateTimeUtility.TimeSpanToString(timeSpan)}'" :
         value.ToString();
 }
예제 #2
0
 public VarEntry(string name, Memezo.Value value)
 {
     this.Name  = name;
     this.Value = value;
 }
예제 #3
0
        private Memezo.Value BinaryOperation(Memezo.Value first, Memezo.Value second, Memezo.TokenType tokenType)
        {
            DateTime firstDateTime  = DateTime.MinValue;
            DateTime secondDateTime = DateTime.MinValue;
            TimeSpan firstTimeSpan  = TimeSpan.MinValue;
            TimeSpan secondTimeSpan = TimeSpan.MinValue;

            var firstType =
                (first.DataType == Memezo.DataType.Number) ? ContentType.Number :
                DateTimeUtility.TryParseDateTime(first.String, out firstDateTime) ? ContentType.DateTime :
                DateTimeUtility.TryParseTimeSpan(first.String, out firstTimeSpan) ? ContentType.TimeSpan :
                ContentType.String;
            var secondType =
                (second.DataType == Memezo.DataType.Number) ? ContentType.Number :
                DateTimeUtility.TryParseDateTime(second.String, out secondDateTime) ? ContentType.DateTime :
                DateTimeUtility.TryParseTimeSpan(second.String, out secondTimeSpan) ? ContentType.TimeSpan :
                ContentType.String;

            if (firstType == ContentType.DateTime && secondType == ContentType.DateTime)
            {
                if (tokenType == Memezo.TokenType.Minus)
                {
                    var span = firstDateTime - secondDateTime;
                    return(new Memezo.Value(DateTimeUtility.TimeSpanToString(span)));
                }
            }
            else if (firstType == ContentType.DateTime && secondType == ContentType.TimeSpan)
            {
                if (tokenType == Memezo.TokenType.Plus || tokenType == Memezo.TokenType.Minus)
                {
                    var date = (tokenType == Memezo.TokenType.Plus) ?
                               (firstDateTime + secondTimeSpan) :
                               (firstDateTime - secondTimeSpan);
                    return(new Memezo.Value(DateTimeUtility.DateTimeToString(date)));
                }
            }
            else if (firstType == ContentType.TimeSpan && secondType == ContentType.TimeSpan)
            {
                if (tokenType == Memezo.TokenType.Plus || tokenType == Memezo.TokenType.Minus)
                {
                    var span = (tokenType == Memezo.TokenType.Plus) ?
                               (firstTimeSpan + secondTimeSpan) :
                               (firstTimeSpan - secondTimeSpan);
                    return(new Memezo.Value(DateTimeUtility.TimeSpanToString(span)));
                }
            }
            else if (firstType == ContentType.TimeSpan && secondType == ContentType.Number)
            {
                if (tokenType == Memezo.TokenType.Multiply || tokenType == Memezo.TokenType.Division)
                {
                    var ticks = (tokenType == Memezo.TokenType.Multiply) ?
                                (firstTimeSpan.Ticks * second.Number) :
                                (firstTimeSpan.Ticks / second.Number);
                    if (ticks < long.MinValue || long.MaxValue < ticks)
                    {
                        throw new OverflowException();
                    }
                    return(new Memezo.Value(DateTimeUtility.TimeSpanToString(new TimeSpan((long)ticks))));
                }
            }
            else
            {
                ;
            }
            return(null);
        }
예제 #4
0
 private Memezo.Value UnaryOperation(Memezo.Value first, Memezo.TokenType tokenType) => null;