Esempio n. 1
0
        private static string ConvertDateTimeRange(TimexProperty timex, System.DateTime date)
        {
            if (timex.Year != null && timex.Month != null && timex.DayOfMonth != null)
            {
                var timexDate = new System.DateTime(timex.Year.Value, timex.Month.Value, timex.DayOfMonth.Value);

                if (timex.PartOfDay != null)
                {
                    if (TimexDateHelpers.DatePartEquals(timexDate, date))
                    {
                        if (timex.PartOfDay == "NI")
                        {
                            return("tonight");
                        }
                        else
                        {
                            return($"this {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                        }
                    }

                    var tomorrow = TimexDateHelpers.Tomorrow(date);
                    if (TimexDateHelpers.DatePartEquals(timexDate, tomorrow))
                    {
                        return($"tomorrow {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    var yesterday = TimexDateHelpers.Yesterday(date);
                    if (TimexDateHelpers.DatePartEquals(timexDate, yesterday))
                    {
                        return($"yesterday {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    if (TimexDateHelpers.IsNextWeek(timexDate, date))
                    {
                        return($"next {GetDateDay(timexDate.DayOfWeek)} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    if (TimexDateHelpers.IsLastWeek(timexDate, date))
                    {
                        return($"last {GetDateDay(timexDate.DayOfWeek)} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }
                }
            }

            return(string.Empty);
        }
        private static string ConvertDateTimeRange(TimexProperty timex, DateObject date)
        {
            if (timex.Year != null && timex.Month != null && timex.DayOfMonth != null)
            {
                var timexDate = new DateObject(timex.Year.Value, timex.Month.Value, timex.DayOfMonth.Value);

                if (timex.PartOfDay != null)
                {
                    if (TimexDateHelpers.DatePartEquals(timexDate, date))
                    {
                        if (timex.PartOfDay == Constants.TimexNight)
                        {
                            return(TimexConstantsEnglish.Tonight);
                        }
                        else
                        {
                            return($"{TimexConstantsEnglish.This} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                        }
                    }

                    var tomorrow = TimexDateHelpers.Tomorrow(date);
                    if (TimexDateHelpers.DatePartEquals(timexDate, tomorrow))
                    {
                        return($"{TimexConstantsEnglish.Tomorrow} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    var yesterday = TimexDateHelpers.Yesterday(date);
                    if (TimexDateHelpers.DatePartEquals(timexDate, yesterday))
                    {
                        return($"{TimexConstantsEnglish.Yesterday} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    if (TimexDateHelpers.IsNextWeek(timexDate, date))
                    {
                        return($"{TimexConstantsEnglish.Next} {GetDateDay(timexDate.DayOfWeek)} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }

                    if (TimexDateHelpers.IsLastWeek(timexDate, date))
                    {
                        return($"{TimexConstantsEnglish.Last} {GetDateDay(timexDate.DayOfWeek)} {TimexConstantsEnglish.DayParts[timex.PartOfDay]}");
                    }
                }
            }

            return(string.Empty);
        }
Esempio n. 3
0
        private static string ConvertDate(TimexProperty timex, System.DateTime date)
        {
            if (timex.Year != null && timex.Month != null && timex.DayOfMonth != null)
            {
                var timexDate = new System.DateTime(timex.Year.Value, timex.Month.Value, timex.DayOfMonth.Value);

                if (TimexDateHelpers.DatePartEquals(timexDate, date))
                {
                    return("today");
                }

                var tomorrow = TimexDateHelpers.Tomorrow(date);
                if (TimexDateHelpers.DatePartEquals(timexDate, tomorrow))
                {
                    return("tomorrow");
                }

                var yesterday = TimexDateHelpers.Yesterday(date);
                if (TimexDateHelpers.DatePartEquals(timexDate, yesterday))
                {
                    return("yesterday");
                }

                if (TimexDateHelpers.IsThisWeek(timexDate, date))
                {
                    return($"this {GetDateDay(timexDate.DayOfWeek)}");
                }

                if (TimexDateHelpers.IsNextWeek(timexDate, date))
                {
                    return($"next {GetDateDay(timexDate.DayOfWeek)}");
                }

                if (TimexDateHelpers.IsLastWeek(timexDate, date))
                {
                    return($"last {GetDateDay(timexDate.DayOfWeek)}");
                }
            }

            return(TimexConvertEnglish.ConvertDate(timex));
        }
        private static string ConvertDate(TimexProperty timex, DateObject date)
        {
            if (timex.Year != null && timex.Month != null && timex.DayOfMonth != null)
            {
                var timexDate = new DateObject(timex.Year.Value, timex.Month.Value, timex.DayOfMonth.Value);

                if (TimexDateHelpers.DatePartEquals(timexDate, date))
                {
                    return(TimexConstantsEnglish.Today);
                }

                var tomorrow = TimexDateHelpers.Tomorrow(date);
                if (TimexDateHelpers.DatePartEquals(timexDate, tomorrow))
                {
                    return(TimexConstantsEnglish.Tomorrow);
                }

                var yesterday = TimexDateHelpers.Yesterday(date);
                if (TimexDateHelpers.DatePartEquals(timexDate, yesterday))
                {
                    return(TimexConstantsEnglish.Yesterday);
                }

                if (TimexDateHelpers.IsThisWeek(timexDate, date))
                {
                    return($"{TimexConstantsEnglish.This} {GetDateDay(timexDate.DayOfWeek)}");
                }

                if (TimexDateHelpers.IsNextWeek(timexDate, date))
                {
                    return($"{TimexConstantsEnglish.Next} {GetDateDay(timexDate.DayOfWeek)}");
                }

                if (TimexDateHelpers.IsLastWeek(timexDate, date))
                {
                    return($"{TimexConstantsEnglish.Last} {GetDateDay(timexDate.DayOfWeek)}");
                }
            }

            return(TimexConvertEnglish.ConvertDate(timex));
        }