public DateTimeParseResult Parse(ExtractResult er, DateObject referenceTime) { object value = null; if (er.Type.Equals(ParserName)) { DateTimeResolutionResult innerResult; // Resolve timezome if (TimeZoneUtility.ShouldResolveTimeZone(er, config.Options)) { var metadata = er.Data as Dictionary <string, object>; var timezoneEr = metadata[Constants.SYS_DATETIME_TIMEZONE] as ExtractResult; var timezonePr = config.TimeZoneParser.Parse(timezoneEr); innerResult = InternalParse(er.Text.Substring(0, (int)(er.Text.Length - timezoneEr.Length)), referenceTime); if (timezonePr != null && timezonePr.Value != null) { innerResult.TimeZoneResolution = ((DateTimeResolutionResult)timezonePr.Value).TimeZoneResolution; } } else { innerResult = InternalParse(er.Text, referenceTime); } if (innerResult.Success) { innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, DateTimeFormatUtil.FormatTime((DateObject)innerResult.FutureValue) } }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, DateTimeFormatUtil.FormatTime((DateObject)innerResult.PastValue) } }; value = innerResult; } } var ret = new DateTimeParseResult { Text = er.Text, Start = er.Start, Length = er.Length, Type = er.Type, Data = er.Data, Value = value, TimexStr = value == null ? "" : ((DateTimeResolutionResult)value).Timex, ResolutionStr = "" }; return(ret); }
public DateTimeParseResult Parse(ExtractResult er, DateObject refTime) { var referenceTime = refTime; object value = null; if (er.Type.Equals(ParserName)) { var innerResult = InternalParse(er.Text, referenceTime); // Handling timeZone if (innerResult.Success && TimeZoneUtility.ShouldResolveTimeZone(er, this.Config.Options)) { var metadata = er.Data as Dictionary <string, object>; var timezoneEr = metadata[Constants.SYS_DATETIME_TIMEZONE] as ExtractResult; var timezonePr = this.Config.TimeZoneParser.Parse(timezoneEr); if (timezonePr != null && timezonePr.Value != null) { innerResult.TimeZoneResolution = ((DateTimeResolutionResult)timezonePr.Value).TimeZoneResolution; } } if (innerResult.Success) { if (!IsBeforeOrAfterMod(innerResult.Mod)) { innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.START_DATETIME, DateTimeFormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)innerResult.FutureValue).Item1) }, { TimeTypeConstants.END_DATETIME, DateTimeFormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)innerResult.FutureValue).Item2) }, }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.START_DATETIME, DateTimeFormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)innerResult.PastValue).Item1) }, { TimeTypeConstants.END_DATETIME, DateTimeFormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)innerResult.PastValue).Item2) }, }; } else { if (innerResult.Mod == Constants.AFTER_MOD) { // Cases like "1/1/2015 after 2:00" there is no EndTime innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.START_DATETIME, DateTimeFormatUtil.FormatDateTime((DateObject)innerResult.FutureValue) }, }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.START_DATETIME, DateTimeFormatUtil.FormatDateTime((DateObject)innerResult.PastValue) }, }; } else { // Cases like "1/1/2015 before 5:00 in the afternoon" there is no StartTime innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.END_DATETIME, DateTimeFormatUtil.FormatDateTime((DateObject)innerResult.FutureValue) }, }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.END_DATETIME, DateTimeFormatUtil.FormatDateTime((DateObject)innerResult.PastValue) }, }; } } value = innerResult; } } var ret = new DateTimeParseResult { Text = er.Text, Start = er.Start, Length = er.Length, Type = er.Type, Data = er.Data, Value = value, TimexStr = value == null ? string.Empty : ((DateTimeResolutionResult)value).Timex, ResolutionStr = string.Empty, }; return(ret); }