コード例 #1
0
        public void DataTypes_Helpers_ExpandDateTimeRange_Year()
        {
            var timex = new TimexProperty("1999");
            var range = TimexHelpers.ExpandDateTimeRange(timex);

            Assert.AreEqual("1999-01-01", range.Start.TimexValue);
            Assert.AreEqual("2000-01-01", range.End.TimexValue);
        }
コード例 #2
0
        public void DataTypes_Helpers_ExpandDateTimeRange_Month()
        {
            var timex = new TimexProperty("2017-05");
            var range = TimexHelpers.ExpandDateTimeRange(timex);

            Assert.AreEqual("2017-05-01", range.Start.TimexValue);
            Assert.AreEqual("2017-06-01", range.End.TimexValue);
        }
コード例 #3
0
        public void DataTypes_Helpers_ExpandDateTimeRange_Include_Time()
        {
            var timex = new TimexProperty("(2017-10-10T16:02:04,2017-10-10T16:07:04,PT5M)");
            var range = TimexHelpers.ExpandDateTimeRange(timex);

            Assert.AreEqual("2017-10-10T16:02:04", range.Start.TimexValue);
            Assert.AreEqual("2017-10-10T16:07:04", range.End.TimexValue);
        }
コード例 #4
0
        public void DataTypes_Helpers_ExpandDateTimeRange_Long()
        {
            var timex = new TimexProperty("(2006-01-01,2008-06-01,P882D)");
            var range = TimexHelpers.ExpandDateTimeRange(timex);

            Assert.AreEqual("2006-01-01", range.Start.TimexValue);
            Assert.AreEqual("2008-06-01", range.End.TimexValue);
        }
コード例 #5
0
        public void DataTypes_Helpers_ExpandDateTimeRange_Short()
        {
            var timex = new TimexProperty("(2017-09-27,2017-09-29,P2D)");
            var range = TimexHelpers.ExpandDateTimeRange(timex);

            Assert.AreEqual("2017-09-27", range.Start.TimexValue);
            Assert.AreEqual("2017-09-29", range.End.TimexValue);
        }
コード例 #6
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);
        }