Exemple #1
0
        public void EvalDayOfWeek(RCRunner runner, RCClosure closure, RCTime right)
        {
            RCArray <string> result = new RCArray <string> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                DateTime date = new DateTime(right[i].Ticks);
                result.Write(date.DayOfWeek.ToString());
            }
            runner.Yield(closure, new RCString(result));
        }
Exemple #2
0
        public void EvalNow(RCRunner runner, RCClosure closure, RCTime right)
        {
            RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                DateTime date         = new DateTime(right[i].Ticks);
                DateTime adjustedDate = date.ToLocalTime();
                result.Write(new RCTimeScalar(adjustedDate, right[i].Type));
            }
            runner.Yield(closure, new RCTime(result));
        }
Exemple #3
0
        public void EvalTime(RCRunner runner, RCClosure closure, RCSymbol left, RCTime right)
        {
            RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> ();
            string     name = left[0].Part(0).ToString();
            RCTimeType type = (RCTimeType)Enum.Parse(typeof(RCTimeType), name, true);

            for (int i = 0; i < right.Count; ++i)
            {
                result.Write(new RCTimeScalar(new DateTime(right[i].Ticks), type));
            }
            runner.Yield(closure, new RCTime(result));
        }
Exemple #4
0
        public void EvalToDisplayTime(RCRunner runner, RCClosure closure, RCTime right)
        {
            RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                DateTime utcDateTime      = new DateTime(right[i].Ticks);
                DateTime adjustedDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime,
                                                                            RCTime.DisplayTimeZone);
                result.Write(new RCTimeScalar(adjustedDateTime, right[i].Type));
            }
            runner.Yield(closure, new RCTime(result));
        }
Exemple #5
0
        public void EvalNextDay(RCRunner runner, RCClosure closure, RCTime left, RCLong right)
        {
            if (right.Count != 1)
            {
                throw new Exception("Only one number of days to add allowed");
            }
            RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (left.Count);

            for (int i = 0; i < left.Count; ++i)
            {
                DateTime date = new DateTime(left[i].Ticks).AddDays(right[0]);
                result.Write(new RCTimeScalar(date, left[i].Type));
            }
            runner.Yield(closure, new RCTime(result));
        }
Exemple #6
0
        public void EvalNetformat(RCRunner runner, RCClosure closure, RCString left, RCTime right)
        {
            RCArray <DateTime> source = new RCArray <DateTime> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                if (right[i].Type == RCTimeType.Timespan)
                {
                    throw new Exception(
                              "netformat does not handle Timespans, please pass a specific date and time.");
                }
                source.Write(new DateTime(right[i].Ticks));
            }
            runner.Yield(closure, new RCString(DoNetFormat <DateTime> (left, source)));
        }
Exemple #7
0
        public void EvalNextDayOfWeek(RCRunner runner, RCClosure closure, RCTime left, RCString right)
        {
            if (right.Count != 1)
            {
                throw new Exception("Only one day of week allowed");
            }
            RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (left.Count);
            DayOfWeek dayOfWeek           = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), right[0], ignoreCase: true);

            for (int i = 0; i < left.Count; ++i)
            {
                DateTime date       = new DateTime(left[i].Ticks);
                int      daysUntil  = dayOfWeek - date.DayOfWeek;
                DateTime targetDate = date;
                if (daysUntil < 0)
                {
                    daysUntil += 7;
                }
                targetDate = date.AddDays(daysUntil);
                result.Write(new RCTimeScalar(targetDate, RCTimeType.Date));
            }
            runner.Yield(closure, new RCTime(result));
        }
Exemple #8
0
 public void EvalPop(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoPop <RCTimeScalar> (right.Data)));
 }
Exemple #9
0
 public void EvalFirst(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCTime(right[0]));
 }
Exemple #10
0
 public void EvalOperator(RCRunner runner, RCClosure closure, RCTime left, RCTime right)
 {
     runner.Yield(closure, DoFind <RCTimeScalar> (left, right));
 }
Exemple #11
0
 public void EvalLast(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCTime(right[right.Count - 1]));
 }
Exemple #12
0
 public void EvalCount(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCLong(right.Count));
 }
Exemple #13
0
 public void EvalRepeat(RCRunner runner, RCClosure closure, RCLong left, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoRepeat <RCTimeScalar> (left, right)));
 }
Exemple #14
0
 public void EvalOperator(RCRunner runner, RCClosure closure, RCTime left, RCDecimal right)
 {
     runner.Yield(closure, DoAt <RCTimeScalar> (closure, left, right));
 }
Exemple #15
0
 public void EvalShuffle(RCRunner runner, RCClosure closure, RCLong left, RCTime right)
 {
     runner.Yield(closure,
                  new RCTime(DoShuffle <RCTimeScalar> (new Random((int)left[0]),
                                                       right)));
 }
Exemple #16
0
 public void EvalAppend(RCRunner runner, RCClosure closure, RCTime left, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoAppend <RCTimeScalar> (left, right)));
 }
Exemple #17
0
 public void EvalColoft(RCRunner runner, RCClosure closure, RCTime left, RCCube right)
 {
     runner.Yield(closure, new RCTime(right.DoColof <RCTimeScalar> (0, left[0], true)));
 }
Exemple #18
0
 public void EvalRange(RCRunner runner, RCClosure closure, RCLong left, RCTime right)
 {
     runner.Yield(closure, DoRange <RCTimeScalar> (left, right));
 }
Exemple #19
0
 public void EvalRank(RCRunner runner, RCClosure closure, RCSymbol left, RCTime right)
 {
     runner.Yield(closure,
                  new RCLong(RankUtils.DoRank <RCTimeScalar> (Sort.ToDir(left),
                                                              right)));
 }
Exemple #20
0
 public void EvalUnique(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoUnique <RCTimeScalar> (right)));
 }
Exemple #21
0
 public void EvalWhere(RCRunner runner, RCClosure closure, RCTime left, RCBoolean right)
 {
     runner.Yield(closure, DoWhere <RCTimeScalar> (left, right));
 }
Exemple #22
0
 public void EvalFrom(RCRunner runner, RCClosure closure, RCByte left, RCTime right)
 {
     runner.Yield(closure, DoAt <RCTimeScalar> (closure, right, left));
 }
Exemple #23
0
 public void EvalExcept(RCRunner runner, RCClosure closure, RCTime left, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoExcept <RCTimeScalar> (left, right)));
 }
Exemple #24
0
        public void EvalAppend(RCRunner runner, RCClosure closure, RCBlock right)
        {
            if (right.Count == 0)
            {
                runner.Yield(closure, RCBlock.Empty);
            }
            RCValue      first  = right.Get(0);
            RCVectorBase vector = first as RCVectorBase;

            if (vector != null)
            {
                RCVectorBase result;
                switch (vector.TypeCode)
                {
                case 'x': result = new RCByte(DoAppend <byte> (right)); break;

                case 'l': result = new RCLong(DoAppend <long> (right)); break;

                case 'd': result = new RCDouble(DoAppend <double> (right)); break;

                case 'm': result = new RCDecimal(DoAppend <decimal> (right)); break;

                case 's': result = new RCString(DoAppend <string> (right)); break;

                case 'b': result = new RCBoolean(DoAppend <bool> (right)); break;

                case 'y': result = new RCSymbol(DoAppend <RCSymbolScalar> (right)); break;

                case 't': result = new RCTime(DoAppend <RCTimeScalar> (right)); break;

                default: throw new Exception("Type:" + vector.TypeCode + " is not supported by sort");
                }
                runner.Yield(closure, result);
                return;
            }
            RCCube cube = first as RCCube;

            if (cube != null)
            {
                RCCube result = new RCCube(cube);
                for (int i = 1; i < right.Count; ++i)
                {
                    Writer writer = new Writer(result, null, true, true, 0);
                    writer.Write((RCCube)right.Get(i));
                }
                runner.Yield(closure, result);
                return;
            }
            // Individual values are now appended to the result just like the children of
            // blocks.
            {
                RCBlock result = RCBlock.Empty;
                for (int i = 0; i < right.Count; ++i)
                {
                    RCBlock top = right.GetName(i);
                    if (top.Value is RCBlock)
                    {
                        RCBlock list = (RCBlock)right.Get(i);
                        for (int j = 0; j < list.Count; ++j)
                        {
                            RCBlock item = list.GetName(j);
                            result = new RCBlock(result, item.Name, ":", item.Value);
                        }
                    }
                    else
                    {
                        result = new RCBlock(result, top.Name, ":", top.Value);
                    }
                }
                runner.Yield(closure, result);
            }
        }
Exemple #25
0
 public void EvalSort(RCRunner runner, RCClosure closure, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoSort <RCTimeScalar> (SortDirection.asc, right)));
 }
Exemple #26
0
 public void EvalSort(RCRunner runner, RCClosure closure, RCSymbol left, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoSort <RCTimeScalar> (ToDir(left), right)));
 }
Exemple #27
0
 public void EvalUnion(RCRunner runner, RCClosure closure, RCTime left, RCTime right)
 {
     runner.Yield(closure, new RCTime(DoUnion <RCTimeScalar> (left, right)));
 }
Exemple #28
0
 public void EvalEach(RCRunner runner, RCClosure closure, RCBlock left, RCTime right)
 {
     DoEach <RCTimeScalar> (runner, closure, left, right);
 }