Ejemplo n.º 1
0
        public void LoadTimeCriteria(LuisResult result, TimeZoneInfo timezone)
        {
            var timeRange = result.ParseTimeRange(timezone);
            var time      = result.ParseTime(timezone);
            var duration  = result.ParseDuration();

            var start = timeRange.HasValue
                ? timeRange.Value.start
                : time.Length >= 1
                    ? time[0]
                    : time.Length == 1 && duration.HasValue
                        ? time[0]
                        : (DateTimeOffset?)null;

            if (start.HasValue && start >= DateTime.Now.AddSeconds(-10) && start <= DateTime.Now.AddSeconds(10))
            {
                // user said "now".. let's adjust a bit
                start = GetAssumedStartTime(start.Value);
            }
            while (start.HasValue && start < DateTime.Now.AddMinutes(-15))
            {
                start = start.Value.AddDays(1);
            }

            var end = timeRange.HasValue
                ? timeRange.Value.end
                : time.Length >= 2
                    ? time[1]
                    : duration.HasValue && start.HasValue
                        ? start.Value.Add(duration.Value)
                        : (DateTimeOffset?)null;

            while (end.HasValue && end < DateTime.Now.AddMinutes(-15))
            {
                end = end.Value.AddDays(1);
            }

            this.StartTime = start;
            this.EndTime   = end;
        }