Пример #1
0
        public static string ConvertTimexToStringRelative(TimexProperty timex, System.DateTime date)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.DateTimeRange))
            {
                return(ConvertDateTimeRange(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.DateRange))
            {
                return(ConvertDateRange(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.DateTime))
            {
                return(ConvertDateTime(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.Date))
            {
                return(ConvertDate(timex, date));
            }

            return(TimexConvert.ConvertTimexToString(timex));
        }
Пример #2
0
        private static List <Resolution.Entry> ResolveTimex(TimexProperty timex, DateObject date)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.DateTimeRange))
            {
                return(ResolveDateTimeRange(timex));
            }

            if (types.Contains(Constants.TimexTypes.Definite) && types.Contains(Constants.TimexTypes.Time))
            {
                return(ResolveDefiniteTime(timex));
            }

            if (types.Contains(Constants.TimexTypes.Definite) && types.Contains(Constants.TimexTypes.DateRange))
            {
                return(ResolveDefiniteDateRange(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.DateRange))
            {
                return(ResolveDateRange(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.Definite))
            {
                return(ResolveDefinite(timex));
            }

            if (types.Contains(Constants.TimexTypes.TimeRange))
            {
                return(ResolveTimeRange(timex));
            }

            if (types.Contains(Constants.TimexTypes.DateTime))
            {
                return(ResolveDateTime(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.Duration))
            {
                return(ResolveDuration(timex));
            }

            if (types.Contains(Constants.TimexTypes.Date))
            {
                return(ResolveDate(timex, date));
            }

            if (types.Contains(Constants.TimexTypes.Time))
            {
                return(ResolveTime(timex));
            }

            return(new List <Resolution.Entry>());
        }
Пример #3
0
        public static string Format(TimexProperty timex)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.Present))
            {
                return("PRESENT_REF");
            }

            if ((types.Contains(Constants.TimexTypes.DateTimeRange) || types.Contains(Constants.TimexTypes.DateRange) ||
                 types.Contains(Constants.TimexTypes.TimeRange)) && types.Contains(Constants.TimexTypes.Duration))
            {
                var range = TimexHelpers.ExpandDateTimeRange(timex);
                return($"({Format(range.Start)},{Format(range.End)},{Format(range.Duration)})");
            }

            if (types.Contains(Constants.TimexTypes.DateTimeRange))
            {
                return($"{FormatDate(timex)}{FormatTimeRange(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.DateRange))
            {
                return($"{FormatDateRange(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.TimeRange))
            {
                return($"{FormatTimeRange(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.DateTime))
            {
                return($"{FormatDate(timex)}{FormatTime(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.Duration))
            {
                return($"{FormatDuration(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.Date))
            {
                return($"{FormatDate(timex)}");
            }

            if (types.Contains(Constants.TimexTypes.Time))
            {
                return($"{FormatTime(timex)}");
            }

            return(string.Empty);
        }
Пример #4
0
        public static TimexRange ExpandDateTimeRange(TimexProperty timex)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.Duration))
            {
                var start    = CloneDateTime(timex);
                var duration = CloneDuration(timex);
                return(new TimexRange
                {
                    Start = start,
                    End = TimexDateTimeAdd(start, duration),
                    Duration = duration
                });
            }
            else
            {
                if (timex.Year != null)
                {
                    var range = new TimexRange {
                        Start = new TimexProperty {
                            Year = timex.Year
                        }, End = new TimexProperty()
                    };
                    if (timex.Month != null)
                    {
                        range.Start.Month      = timex.Month;
                        range.Start.DayOfMonth = 1;
                        range.End.Year         = timex.Year;
                        range.End.Month        = timex.Month + 1;
                        range.End.DayOfMonth   = 1;
                    }
                    else
                    {
                        range.Start.Month      = 1;
                        range.Start.DayOfMonth = 1;
                        range.End.Year         = timex.Year + 1;
                        range.End.Month        = 1;
                        range.End.DayOfMonth   = 1;
                    }

                    return(range);
                }
            }

            return(new TimexRange {
                Start = new TimexProperty(), End = new TimexProperty()
            });
        }
Пример #5
0
        public static string ConvertTimexToString(TimexProperty timex)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.Present))
            {
                return("now");
            }

            if (types.Contains(Constants.TimexTypes.DateTimeRange))
            {
                return(ConvertDateTimeRange(timex));
            }

            if (types.Contains(Constants.TimexTypes.DateRange))
            {
                return(ConvertDateRange(timex));
            }

            if (types.Contains(Constants.TimexTypes.Duration))
            {
                return(ConvertDuration(timex));
            }

            if (types.Contains(Constants.TimexTypes.TimeRange))
            {
                return(ConvertTimeRange(timex));
            }

            // TODO: where appropriate delegate most the formatting delegate to Date.toLocaleString(options)

            if (types.Contains(Constants.TimexTypes.DateTime))
            {
                return(ConvertDateTime(timex));
            }

            if (types.Contains(Constants.TimexTypes.Date))
            {
                return(ConvertDate(timex));
            }

            if (types.Contains(Constants.TimexTypes.Time))
            {
                return(ConvertTime(timex));
            }

            return(string.Empty);
        }
Пример #6
0
        public static TimexRange ExpandDateTimeRange(TimexProperty timex)
        {
            var types = timex.Types.Count != 0 ? timex.Types : TimexInference.Infer(timex);

            if (types.Contains(Constants.TimexTypes.Duration))
            {
                var start    = CloneDateTime(timex);
                var duration = CloneDuration(timex);
                return(new TimexRange
                {
                    Start = start,
                    End = TimexDateTimeAdd(start, duration),
                    Duration = duration,
                });
            }
            else
            {
                if (timex.Year != null)
                {
                    Tuple <TimexProperty, TimexProperty> dateRange;
                    if (timex.Month != null && timex.WeekOfMonth != null)
                    {
                        dateRange = MonthWeekDateRange(timex.Year.Value, timex.Month.Value, timex.WeekOfMonth.Value);
                    }
                    else if (timex.Month != null)
                    {
                        dateRange = MonthDateRange(timex.Year.Value, timex.Month.Value);
                    }
                    else if (timex.WeekOfYear != null)
                    {
                        dateRange = YearWeekDateRange(timex.Year.Value, timex.WeekOfYear.Value, timex.Weekend);
                    }
                    else
                    {
                        dateRange = YearDateRange(timex.Year.Value);
                    }

                    return(new TimexRange {
                        Start = dateRange.Item1, End = dateRange.Item2
                    });
                }
            }

            return(new TimexRange {
                Start = new TimexProperty(), End = new TimexProperty()
            });
        }