public static string DateValue(TimexProperty timexProperty)
        {
            if (timexProperty.Year != null && timexProperty.Month != null && timexProperty.DayOfMonth != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timexProperty.Year, 4)}-{TimexDateHelpers.FixedFormatNumber(timexProperty.Month, 2)}-{TimexDateHelpers.FixedFormatNumber(timexProperty.DayOfMonth, 2)}");
            }

            return(string.Empty);
        }
Beispiel #2
0
        private static string FormatDateRange(TimexProperty timex)
        {
            if (timex.Year != null && timex.WeekOfYear != null && timex.Weekend != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-W{TimexDateHelpers.FixedFormatNumber(timex.WeekOfYear, 2)}-WE");
            }

            if (timex.Year != null && timex.WeekOfYear != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-W{TimexDateHelpers.FixedFormatNumber(timex.WeekOfYear, 2)}");
            }

            if (timex.Year != null && timex.Month != null && timex.WeekOfMonth != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}-W{TimexDateHelpers.FixedFormatNumber(timex.WeekOfMonth, 2)}");
            }

            if (timex.Year != null && timex.Season != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-{timex.Season}");
            }

            if (timex.Season != null)
            {
                return($"{timex.Season}");
            }

            if (timex.Year != null && timex.Month != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}");
            }

            if (timex.Year != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}");
            }

            if (timex.Month != null && timex.WeekOfMonth != null && timex.DayOfWeek != null)
            {
                return($"{Constants.TimexFuzzyYear}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}-{Constants.TimexFuzzyWeek}-{timex.WeekOfMonth}-{timex.DayOfWeek}");
            }

            if (timex.Month != null && timex.WeekOfMonth != null)
            {
                return($"{Constants.TimexFuzzyYear}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}-W{timex.WeekOfMonth?.ToString("D2", CultureInfo.InvariantCulture)}");
            }

            if (timex.Month != null)
            {
                return($"{Constants.TimexFuzzyYear}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}");
            }

            return(string.Empty);
        }
Beispiel #3
0
        private static string FormatTime(TimexProperty timex)
        {
            if (timex.Minute == 0 && timex.Second == 0)
            {
                return($"T{TimexDateHelpers.FixedFormatNumber(timex.Hour, 2)}");
            }

            if (timex.Second == 0)
            {
                return($"T{TimexDateHelpers.FixedFormatNumber(timex.Hour, 2)}:{TimexDateHelpers.FixedFormatNumber(timex.Minute, 2)}");
            }

            return($"T{TimexDateHelpers.FixedFormatNumber(timex.Hour, 2)}:{TimexDateHelpers.FixedFormatNumber(timex.Minute, 2)}:{TimexDateHelpers.FixedFormatNumber(timex.Second, 2)}");
        }
Beispiel #4
0
        public static string GenerateDateTimex(int year, int month, int day, bool byWeek)
        {
            var    yearString  = year == Constants.InvalidValue ? Constants.TimexFuzzyYear : TimexDateHelpers.FixedFormatNumber(year, 4);
            var    monthString = month == Constants.InvalidValue ? Constants.TimexFuzzyMonth : TimexDateHelpers.FixedFormatNumber(month, 2);
            string dayString;

            if (byWeek)
            {
                dayString   = day.ToString(CultureInfo.InvariantCulture);
                monthString = Constants.TimexWeek + monthString;
            }
            else
            {
                dayString = day == Constants.InvalidValue ? Constants.TimexDay : TimexDateHelpers.FixedFormatNumber(day, 2);
            }

            return($"{yearString}-{monthString}-{dayString}");
        }
        public static string TimeValue(TimexProperty timexProperty, DateTime date)
        {
            if (timexProperty.Hour != null && timexProperty.Minute != null && timexProperty.Second != null)
            {
                if (date.Kind == DateTimeKind.Utc)
                {
                    var timeString   = $"{TimexDateHelpers.FixedFormatNumber(timexProperty.Hour, 2)}:{TimexDateHelpers.FixedFormatNumber(timexProperty.Minute, 2)}:{TimexDateHelpers.FixedFormatNumber(timexProperty.Second, 2)}";
                    var tempDateTime = DateTime.Parse(timeString);
                    return(tempDateTime.ToUniversalTime().ToString("HH:mm:ss"));
                }
                else
                {
                    return($"{TimexDateHelpers.FixedFormatNumber(timexProperty.Hour, 2)}:{TimexDateHelpers.FixedFormatNumber(timexProperty.Minute, 2)}:{TimexDateHelpers.FixedFormatNumber(timexProperty.Second, 2)}");
                }
            }

            return(string.Empty);
        }
        private static string FormatDate(TimexProperty timex)
        {
            if (timex.Year != null && timex.Month != null && timex.DayOfMonth != null)
            {
                return($"{TimexDateHelpers.FixedFormatNumber(timex.Year, 4)}-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}-{TimexDateHelpers.FixedFormatNumber(timex.DayOfMonth, 2)}");
            }

            if (timex.Month != null && timex.DayOfMonth != null)
            {
                return($"XXXX-{TimexDateHelpers.FixedFormatNumber(timex.Month, 2)}-{TimexDateHelpers.FixedFormatNumber(timex.DayOfMonth, 2)}");
            }

            if (timex.DayOfWeek != null)
            {
                return($"XXXX-WXX-{timex.DayOfWeek}");
            }

            return(string.Empty);
        }