Ejemplo n.º 1
0
        public DateTimeParseResult SetInclusivePeriodEnd(DateTimeParseResult slot)
        {
            if (slot.Type == $"{ParserTypeName}.{Constants.SYS_DATETIME_DATEPERIOD}")
            {
                var timexComponents = slot.TimexStr.Split(Constants.DatePeriodTimexSplitter, StringSplitOptions.RemoveEmptyEntries);

                // Only handle DatePeriod like "(StartDate,EndDate,Duration)"
                if (timexComponents.Length == 3)
                {
                    var value    = (SortedDictionary <string, object>)slot.Value;
                    var altTimex = string.Empty;

                    if (value != null && value.ContainsKey(ResolutionKey.ValueSet))
                    {
                        var valueSet = value[ResolutionKey.ValueSet] as IList <Dictionary <string, string> >;

                        if (valueSet != null && valueSet.Any())
                        {
                            foreach (var values in valueSet)
                            {
                                // This is only a sanity check
                                if (values.ContainsKey(DateTimeResolutionKey.START) && values.ContainsKey(DateTimeResolutionKey.END) && values.ContainsKey(DateTimeResolutionKey.Timex))
                                {
                                    var startDate           = DateObject.Parse(values[DateTimeResolutionKey.START]);
                                    var endDate             = DateObject.Parse(values[DateTimeResolutionKey.END]);
                                    var durationStr         = timexComponents[2];
                                    var datePeriodTimexType = TimexUtility.GetDatePeriodTimexType(durationStr);
                                    endDate = TimexUtility.OffsetDateObject(endDate, offset: 1, timexType: datePeriodTimexType);
                                    var timex = TimexUtility.GenerateDatePeriodTimex(startDate, endDate, datePeriodTimexType);
                                    values[DateTimeResolutionKey.Timex] = TimexUtility.GenerateAlterTimex(slot.TimexStr, timex);
                                    values[DateTimeResolutionKey.END]   = FormatUtil.LuisDate(endDate);

                                    if (string.IsNullOrEmpty(altTimex))
                                    {
                                        altTimex = values[DateTimeResolutionKey.Timex];
                                    }
                                }
                            }
                        }
                    }

                    slot.Value    = value;
                    slot.TimexStr = altTimex;
                }
            }

            return(slot);
        }