public static TimexProperty TimexDateAdd(TimexProperty start, TimexProperty duration) { if (start.DayOfWeek != null) { var end = start.Clone(); if (duration.Days != null) { end.DayOfWeek += (int)duration.Days; } return(end); } if (start.Month != null && start.DayOfMonth != null) { if (duration.Days != null) { if (start.Year != null) { var d = new DateObject(start.Year.Value, start.Month.Value, start.DayOfMonth.Value, 0, 0, 0); d = d.AddDays((double)duration.Days.Value); return(new TimexProperty { Year = d.Year, Month = d.Month, DayOfMonth = d.Day, }); } else { var d = new DateObject(2001, start.Month.Value, start.DayOfMonth.Value, 0, 0, 0); d = d.AddDays((double)duration.Days.Value); return(new TimexProperty { Month = d.Month, DayOfMonth = d.Day, }); } } if (duration.Years != null) { if (start.Year != null) { return(new TimexProperty { Year = (int)(start.Year.Value + duration.Years.Value), Month = start.Month, DayOfMonth = start.DayOfMonth, }); } } if (duration.Months != null) { if (start.Month != null) { return(new TimexProperty { Year = start.Year, Month = (int)(start.Month + duration.Months), DayOfMonth = start.DayOfMonth, }); } } } return(start); }
public static TimexProperty TimexDateTimeAdd(TimexProperty start, TimexProperty duration) { return(TimexTimeAdd(TimexDateAdd(start, duration), duration)); }
private static bool IsTime(TimexProperty timexProperty) { return(timexProperty.Hour != null && timexProperty.Minute != null && timexProperty.Second != null); }
private static bool IsDate(TimexProperty timexProperty) { return((timexProperty.Month != null && timexProperty.DayOfMonth != null) || timexProperty.DayOfWeek != null); }
private static List <Resolution.Entry> ResolveDateRange(TimexProperty timex, DateObject date) { if (timex.Season != null) { return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Value = "not resolved", }, }); } else { if (timex.Month != null && timex.WeekOfMonth != null) { var yearDateRangeList = GetMonthWeekDateRange(timex.Year ?? Constants.InvalidValue, timex.Month.Value, timex.WeekOfMonth.Value, date.Year); var result = new List <Resolution.Entry> { }; foreach (Tuple <string, string> yearDateRange in yearDateRangeList) { result.Add(new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = yearDateRange.Item1, End = yearDateRange.Item2, }); } return(result); } if (timex.Year != null && timex.Month != null) { var dateRange = MonthDateRange(timex.Year.Value, timex.Month.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } if (timex.Year != null && timex.WeekOfYear != null) { var dateRange = YearWeekDateRange(timex.Year.Value, timex.WeekOfYear.Value, timex.Weekend); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } if (timex.Month != null) { var y = date.Year; var lastYearDateRange = MonthDateRange(y - 1, timex.Month.Value); var thisYearDateRange = MonthDateRange(y, timex.Month.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = lastYearDateRange.Item1, End = lastYearDateRange.Item2, }, new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = thisYearDateRange.Item1, End = thisYearDateRange.Item2, }, }); } if (timex.Year != null) { var dateRange = YearDateRange(timex.Year.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } return(new List <Resolution.Entry>()); } }
public static HashSet <string> Infer(TimexProperty timexProperty) { var types = new HashSet <string>(); if (IsPresent(timexProperty)) { types.Add(Constants.TimexTypes.Present); } if (IsDefinite(timexProperty)) { types.Add(Constants.TimexTypes.Definite); } if (IsDate(timexProperty)) { types.Add(Constants.TimexTypes.Date); } if (IsDateRange(timexProperty)) { types.Add(Constants.TimexTypes.DateRange); } if (IsDuration(timexProperty)) { types.Add(Constants.TimexTypes.Duration); } if (IsTime(timexProperty)) { types.Add(Constants.TimexTypes.Time); } if (IsTimeRange(timexProperty)) { types.Add(Constants.TimexTypes.TimeRange); } if (types.Contains(Constants.TimexTypes.Present)) { types.Add(Constants.TimexTypes.Date); types.Add(Constants.TimexTypes.Time); } if (types.Contains(Constants.TimexTypes.Time) && types.Contains(Constants.TimexTypes.Duration)) { types.Add(Constants.TimexTypes.TimeRange); } if (types.Contains(Constants.TimexTypes.Date) && types.Contains(Constants.TimexTypes.Time)) { types.Add(Constants.TimexTypes.DateTime); } if (types.Contains(Constants.TimexTypes.Date) && types.Contains(Constants.TimexTypes.Duration)) { types.Add(Constants.TimexTypes.DateRange); } if (types.Contains(Constants.TimexTypes.DateTime) && types.Contains(Constants.TimexTypes.Duration)) { types.Add(Constants.TimexTypes.DateTimeRange); } if (types.Contains(Constants.TimexTypes.Date) && types.Contains(Constants.TimexTypes.TimeRange)) { types.Add(Constants.TimexTypes.DateTimeRange); } return(types); }
private static bool IsDefinite(TimexProperty timexProperty) { return(timexProperty.Year != null && timexProperty.Month != null && timexProperty.DayOfMonth != null); }
private static string ConvertDateTime(TimexProperty timex, DateObject date) { return($"{ConvertDate(timex, date)} {TimexConvertEnglish.ConvertTime(timex)}"); }
public static string Today(System.DateTime date = default(System.DateTime)) { return(TimexProperty.FromDate(date == default(System.DateTime) ? System.DateTime.Now : date).TimexValue); }
private static bool IsTimeRange(TimexProperty timexProperty) { return(timexProperty.PartOfDay != null); }
private static string FormatDate(TimexProperty timex) { return(TimexHelpers.GenerateDateTimex(timex.Year ?? Constants.InvalidValue, timex.WeekOfYear ?? (timex.Month ?? Constants.InvalidValue), timex.DayOfWeek != null ? timex.DayOfWeek.Value : timex.DayOfMonth ?? Constants.InvalidValue, timex.WeekOfMonth ?? Constants.InvalidValue, timex.DayOfWeek != null)); }
public static string Today(DateObject date = default(DateObject)) { return(TimexProperty.FromDate(date == default(DateObject) ? DateObject.Now : date).TimexValue); }
private static List <Resolution.Entry> ResolveDateRange(TimexProperty timex, DateObject date) { if (timex.Season != null) { return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Value = "not resolved", }, }); } else { if (timex.Year != null && timex.Month != null) { var dateRange = MonthDateRange(timex.Year.Value, timex.Month.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } if (timex.Year != null && timex.WeekOfYear != null) { var dateRange = YearWeekDateRange(timex.Year.Value, timex.WeekOfYear.Value, timex.Weekend); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } if (timex.Month != null && timex.WeekOfMonth != null) { var lastYearDateRange = MonthWeekDateRange(date.Year - 1, timex.Month.Value, timex.WeekOfMonth.Value); var thisYearDateRange = MonthWeekDateRange(date.Year, timex.Month.Value, timex.WeekOfMonth.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = lastYearDateRange.Item1, End = lastYearDateRange.Item2, }, new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = thisYearDateRange.Item1, End = thisYearDateRange.Item2, }, }); } if (timex.Month != null) { var y = date.Year; var lastYearDateRange = MonthDateRange(y - 1, timex.Month.Value); var thisYearDateRange = MonthDateRange(y, timex.Month.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = lastYearDateRange.Item1, End = lastYearDateRange.Item2, }, new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = thisYearDateRange.Item1, End = thisYearDateRange.Item2, }, }); } if (timex.Year != null) { var dateRange = YearDateRange(timex.Year.Value); return(new List <Resolution.Entry> { new Resolution.Entry { Timex = timex.TimexValue, Type = "daterange", Start = dateRange.Item1, End = dateRange.Item2, }, }); } return(new List <Resolution.Entry>()); } }
public static DateObject DateFromTimex(TimexProperty timex) { return(new DateObject(timex.Year ?? 2001, timex.Month ?? 1, timex.DayOfMonth ?? 1, timex.Hour ?? 0, timex.Minute ?? 0, timex.Second ?? 0)); }
private static bool IsPresent(TimexProperty timexProperty) { return(timexProperty.Now == true); }
public static Time TimeFromTimex(TimexProperty timex) { return(new Time(timex.Hour ?? 0, timex.Minute ?? 0, timex.Second ?? 0)); }
private static bool IsDuration(TimexProperty timexProperty) { return(timexProperty.Years != null || timexProperty.Months != null || timexProperty.Weeks != null || timexProperty.Days != null || timexProperty.Hours != null || timexProperty.Minutes != null || timexProperty.Seconds != null); }
public static string DatetimeValue(TimexProperty timexProperty, DateTime date) { return($"{DateValue(timexProperty)} {TimeValue(timexProperty, date)}"); }
public static System.DateTime DateFromTimex(TimexProperty timex) { return(new System.DateTime(timex.Year ?? 2001, timex.Month ?? 1, timex.DayOfMonth ?? 1, timex.Hour ?? 0, timex.Minute ?? 0, timex.Second ?? 0)); }