private static string GetDatePeriodTimexUnitCount(DateObject begin, DateObject end, DatePeriodTimexType timexType)
        {
            string unitCount;

            switch (timexType)
            {
            case DatePeriodTimexType.ByDay:
                unitCount = (end - begin).TotalDays.ToString(CultureInfo.InvariantCulture);
                break;

            case DatePeriodTimexType.ByWeek:
                unitCount = ((end - begin).TotalDays / 7).ToString(CultureInfo.InvariantCulture);
                break;

            case DatePeriodTimexType.ByFortnight:
                unitCount = ((end - begin).TotalDays / 7).ToString(CultureInfo.InvariantCulture);
                break;

            case DatePeriodTimexType.ByMonth:
                unitCount = (((end.Year - begin.Year) * 12) + (end.Month - begin.Month)).ToString(CultureInfo.InvariantCulture);
                break;

            default:
                unitCount = ((end.Year - begin.Year) + ((end.Month - begin.Month) / 12.0)).ToString(CultureInfo.InvariantCulture);
                break;
            }

            return(unitCount);
        }
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType)
        {
            var datePeriodTimex = string.Empty;

            if (timexType == DatePeriodTimexType.ByDay)
            {
                datePeriodTimex = $"P{(end - begin).TotalDays}{Constants.TimexDay}";
            }
            else if (timexType == DatePeriodTimexType.ByWeek)
            {
                datePeriodTimex = $"P{(end - begin).TotalDays / 7}{Constants.TimexWeek}";
            }
            else if (timexType == DatePeriodTimexType.ByMonth)
            {
                var monthDiff = ((end.Year - begin.Year) * 12) + (end.Month - begin.Month);
                datePeriodTimex = $"P{monthDiff}{Constants.TimexMonth}";
            }
            else
            {
                var yearDiff = (end.Year - begin.Year) + (end.Month - begin.Month) / 12.0;
                datePeriodTimex = $"P{yearDiff}{Constants.TimexYear}";
            }

            return($"({FormatUtil.LuisDate(begin)},{FormatUtil.LuisDate(end)},{datePeriodTimex})");
        }
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, string timex1, string timex2)
        {
            var boundaryValid   = !begin.IsDefaultValue() && !end.IsDefaultValue();
            var unitCount       = boundaryValid ? GetDatePeriodTimexUnitCount(begin, end, timexType) : "X";
            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({timex1},{timex2},{datePeriodTimex})");
        }
Exemple #4
0
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, DateObject alternativeBegin = default(DateObject), DateObject alternativeEnd = default(DateObject))
        {
            var equalDurationLength = (end - begin) == (alternativeEnd - alternativeBegin);

            if (alternativeBegin.IsDefaultValue() || alternativeEnd.IsDefaultValue())
            {
                equalDurationLength = true;
            }

            var unitCount = "XX";

            if (equalDurationLength)
            {
                switch (timexType)
                {
                case DatePeriodTimexType.ByDay:
                    unitCount = (end - begin).TotalDays.ToString(CultureInfo.InvariantCulture);
                    break;

                case DatePeriodTimexType.ByWeek:
                    unitCount = ((end - begin).TotalDays / 7).ToString(CultureInfo.InvariantCulture);
                    break;

                case DatePeriodTimexType.ByMonth:
                    unitCount = (((end.Year - begin.Year) * 12) + (end.Month - begin.Month)).ToString(CultureInfo.InvariantCulture);
                    break;

                default:
                    unitCount = ((end.Year - begin.Year) + ((end.Month - begin.Month) / 12.0)).ToString(CultureInfo.InvariantCulture);
                    break;
                }
            }

            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({DateTimeFormatUtil.LuisDate(begin, alternativeBegin)},{DateTimeFormatUtil.LuisDate(end, alternativeEnd)},{datePeriodTimex})");
        }
Exemple #5
0
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, UnspecificDateTimeTerms terms)
        {
            var beginYear  = begin.Year;
            var endYear    = end.Year;
            var beginMonth = begin.Month;
            var endMonth   = end.Month;
            var beginDay   = begin.Day;
            var endDay     = end.Day;

            if ((terms & UnspecificDateTimeTerms.NonspecificYear) != 0)
            {
                beginYear = endYear = -1;
            }

            if ((terms & UnspecificDateTimeTerms.NonspecificMonth) != 0)
            {
                beginMonth = endMonth = -1;
            }

            if ((terms & UnspecificDateTimeTerms.NonspecificDay) != 0)
            {
                beginDay = endDay = -1;
            }

            var unitCount = GetDatePeriodTimexUnitCount(begin, end, timexType);

            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({DateTimeFormatUtil.LuisDate(beginYear, beginMonth, beginDay)},{DateTimeFormatUtil.LuisDate(endYear, endMonth, endDay)},{datePeriodTimex})");
        }
Exemple #6
0
        // TODO: Unify this two methods. This one here detect if "begin/end" have same year, month and day with "alter begin/end" and make them nonspecific.
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, DateObject alternativeBegin = default(DateObject), DateObject alternativeEnd = default(DateObject))
        {
            var equalDurationLength = (end - begin) == (alternativeEnd - alternativeBegin);

            if (alternativeBegin.IsDefaultValue() || alternativeEnd.IsDefaultValue())
            {
                equalDurationLength = true;
            }

            var unitCount = equalDurationLength ? GetDatePeriodTimexUnitCount(begin, end, timexType) : "XX";

            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({DateTimeFormatUtil.LuisDate(begin, alternativeBegin)},{DateTimeFormatUtil.LuisDate(end, alternativeEnd)},{datePeriodTimex})");
        }
Exemple #7
0
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, DateObject alternativeBegin = default(DateObject), DateObject alternativeEnd = default(DateObject))
        {
            var equalDurationLength = ((end - begin) == (alternativeEnd - alternativeBegin));

            if (alternativeBegin.IsDefaultValue() || alternativeEnd.IsDefaultValue())
            {
                equalDurationLength = true;
            }

            var unitCount = "XX";

            if (equalDurationLength)
            {
                if (timexType == DatePeriodTimexType.ByDay)
                {
                    unitCount = (end - begin).TotalDays.ToString();
                }
                else if (timexType == DatePeriodTimexType.ByWeek)
                {
                    unitCount = ((end - begin).TotalDays / 7).ToString();
                }
                else if (timexType == DatePeriodTimexType.ByMonth)
                {
                    unitCount = (((end.Year - begin.Year) * 12) + (end.Month - begin.Month)).ToString();
                }
                else
                {
                    unitCount = ((end.Year - begin.Year) + (end.Month - begin.Month) / 12.0).ToString();
                }
            }

            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({FormatUtil.LuisDate(begin, alternativeBegin)},{FormatUtil.LuisDate(end, alternativeEnd)},{datePeriodTimex})");
        }
        // TODO: Unify this two methods. This one here detect if "begin/end" have same year, month and day with "alter begin/end" and make them nonspecific.
        public static string GenerateDatePeriodTimex(DateObject begin, DateObject end, DatePeriodTimexType timexType, DateObject alternativeBegin = default(DateObject), DateObject alternativeEnd = default(DateObject), bool hasYear = true)
        {
            // If the year is not specified, the combined range timex will use fuzzy years.
            if (!hasYear)
            {
                return(GenerateDatePeriodTimex(begin, end, timexType, UnspecificDateTimeTerms.NonspecificYear));
            }

            var equalDurationLength = (end - begin) == (alternativeEnd - alternativeBegin);

            if (alternativeBegin.IsDefaultValue() || alternativeEnd.IsDefaultValue())
            {
                equalDurationLength = true;
            }

            var unitCount = equalDurationLength ? GetDatePeriodTimexUnitCount(begin, end, timexType) : "XX";

            var datePeriodTimex = $"P{unitCount}{DatePeriodTimexTypeToTimexSuffix[timexType]}";

            return($"({DateTimeFormatUtil.LuisDate(begin, alternativeBegin)},{DateTimeFormatUtil.LuisDate(end, alternativeEnd)},{datePeriodTimex})");
        }