Example #1
0
        public static RCTimeScalar ParseTime(string text, string[] formats, bool smartType)
        {
            DateTime result;

            for (int i = 0; i < formats.Length; ++i)
            {
                if (DateTime.TryParseExact(text,
                                           formats[i],
                                           CultureInfo.InvariantCulture,
                                           // Without this times will implicity have today's
                                           // date.
                                           DateTimeStyles.NoCurrentDateDefault,
                                           out result))
                {
                    if (smartType)
                    {
                        RCTimeType type = RCTime.ALLOWED_FORMAT_TYPES[i];
                        return(new RCTimeScalar(result, type));
                    }
                    else
                    {
                        return(new RCTimeScalar(result, RCTimeType.Timestamp));
                    }
                }
            }
            TimeSpan ts;

            if (TimeSpan.TryParse(text, out ts))
            {
                return(new RCTimeScalar(ts));
            }
            throw new Exception(string.Format("Unable to parse time string: \"{0}\"", text));
        }
Example #2
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));
        }
Example #3
0
 public RCTimeScalar(TimeSpan span)
 {
     Ticks = span.Ticks;
     Type  = RCTimeType.Timespan;
 }
Example #4
0
 public RCTimeScalar(DateTime time, RCTimeType type)
 {
     Ticks = time.Ticks;
     Type  = type;
 }
Example #5
0
 public RCTimeScalar(long ticks, RCTimeType type)
 {
     Ticks = ticks;
     Type  = type;
 }