Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private static string GetTime(string expr, bool roundUp)
        {
            if (string.IsNullOrEmpty(expr))
            {
                return(string.Empty);
            }

            if (DateTimeMathParser.IsDateTime(expr, out DateTime date))
            {
                return(ToUnixTimeMilliseconds(date));
            }

            if (expr == DateTimeMathParser.NOW)
            {
                return(NOW);
            }

            var parts = Regex.Split(expr, @"^now-(\d+)([dhms])$");

            if (parts?.Length > 2)
            {
                int.TryParse(parts [1], out int amount);
                var unit = parts [2];

                return($"{NOW} - {amount}{unit}");
            }

            var res = DateTimeMathParser.ToDateTime(expr, roundUp);

            return(res.HasValue ? ToUnixTimeMilliseconds(res.Value) : string.Empty);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static string GetGroupBy(Time.Range r)
        {
            var from = DateTimeMathParser.ToDateTime(r.From, false);
            var to   = DateTimeMathParser.ToDateTime(r.To, true);

            return((from.HasValue && to.HasValue) ? GetGroupBy(from.Value, to.Value) : "1m");
        }