Ejemplo n.º 1
0
        public DateTimeParseResult Parse(ExtractResult er, DateObject refDate)
        {
            var referenceTime = refDate;
            var extra         = er.Data as DateTimeExtra <PeriodType>;

            if (extra == null)
            {
                var result = new TimeExtractorChs().Extract(er.Text);
                extra = result[0]?.Data as DateTimeExtra <PeriodType>;
            }

            if (extra != null)
            {
                var parseResult = TimePeriodFunctions.Handle(this.config.TimeParser, extra, referenceTime);
                if (parseResult.Success)
                {
                    parseResult.FutureResolution = new Dictionary <string, string>
                    {
                        {
                            TimeTypeConstants.START_TIME,
                            FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)parseResult.FutureValue).Item1)
                        },
                        {
                            TimeTypeConstants.END_TIME,
                            FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)parseResult.FutureValue).Item2)
                        }
                    };

                    parseResult.PastResolution = new Dictionary <string, string>
                    {
                        {
                            TimeTypeConstants.START_TIME,
                            FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)parseResult.PastValue).Item1)
                        },
                        {
                            TimeTypeConstants.END_TIME,
                            FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)parseResult.PastValue).Item2)
                        }
                    };
                }

                var ret = new DateTimeParseResult
                {
                    Start         = er.Start,
                    Text          = er.Text,
                    Type          = er.Type,
                    Length        = er.Length,
                    Value         = parseResult,
                    ResolutionStr = "",
                    TimexStr      = parseResult.Timex
                };

                return(ret);
            }

            return(null);
        }