public static string ToLabelString(
            this MonthFormat format,
            DateTimeSettings currentSettings,
            DateTime sampleTime
            )
        {
            string label;

            if (format == MonthFormat.ThreeLetters)
            {
                label = "Abbreviated";
            }
            else if (format == MonthFormat.FullMonth)
            {
                label = "Full Month";
            }
            else // Number is the default.
            {
                label = "Digit";
            }

            DateTimeSettings settings = currentSettings with {
                MonthFormat = format
            };

            return($"{label} ({sampleTime.ToSettingsString( settings )})");
        }
Exemple #2
0
 public DateTimeFormatter(
     YearFormat yearFormat,
     MonthFormat monthFormat,
     DayFormat dayFormat,
     DayOfWeekFormat dayOfWeekFormat)
 {
     global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.Globalization.DateTimeFormatting.DateTimeFormatter", "DateTimeFormatter.DateTimeFormatter(YearFormat yearFormat, MonthFormat monthFormat, DayFormat dayFormat, DayOfWeekFormat dayOfWeekFormat)");
 }
Exemple #3
0
 public DateTimeFormatter(
     YearFormat yearFormat,
     MonthFormat monthFormat,
     DayFormat dayFormat,
     DayOfWeekFormat dayOfWeekFormat,
     HourFormat hourFormat,
     MinuteFormat minuteFormat,
     SecondFormat secondFormat,
     IEnumerable <string> languages)
 {
     global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.Globalization.DateTimeFormatting.DateTimeFormatter", "DateTimeFormatter.DateTimeFormatter(YearFormat yearFormat, MonthFormat monthFormat, DayFormat dayFormat, DayOfWeekFormat dayOfWeekFormat, HourFormat hourFormat, MinuteFormat minuteFormat, SecondFormat secondFormat, IEnumerable<string> languages)");
 }
Exemple #4
0
        /// <summary>
        /// Creates a DateTimeFormatter object that is initialized with year, month, day, and day of week formats.
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="yearFormat">The desired year format to include in the template.</param>
        /// <param name="monthFormat">The desired month format to include in the template.</param>
        /// <param name="dayFormat">The desired day format to include in the template.</param>
        /// <param name="dayOfWeekFormat">The desired day of week format to include in the template.</param>
        /// <returns></returns>
        public static string Format(this DateTime dt, YearFormat yearFormat, MonthFormat monthFormat, DayFormat dayFormat, DayOfWeekFormat dayOfWeekFormat)
        {
            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter(yearFormat, monthFormat, dayFormat, dayOfWeekFormat);

            return(formatter.Format(dt));
        }
Exemple #5
0
        public static string Format(this DateTime dt, YearFormat yearFormat, MonthFormat monthFormat, DayFormat dayFormat, DayOfWeekFormat dayOfWeekFormat, HourFormat hourFormat, MinuteFormat minuteFormat, SecondFormat secondFormat, IEnumerable <string> languages, string geographicRegion, string calendar, string clock)
        {
            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter(yearFormat, monthFormat, dayFormat, dayOfWeekFormat, hourFormat, minuteFormat, secondFormat, languages, geographicRegion, calendar, clock);

            return(formatter.Format(dt));
        }
        // -------- ToSettingsString --------

        /// <summary>
        /// Reads in the settings and returns a string representation
        /// of the <see cref="DateTime"/> object based on the settings.
        /// </summary>
        public static string ToSettingsString(this DateTime date, DateTimeSettings settings)
        {
            ArgumentNullException.ThrowIfNull(settings, nameof(settings));

            date = date.ToTimeZoneTime(settings);

            DateFormat          dateFormat    = settings.DateFormat;
            MonthFormat         monthFormat   = settings.MonthFormat;
            DateSeparatorFormat dateSepFormat = settings.DateSeparatorFormat;
            TimeFormat          timeFormat    = settings.TimeFormat;

            char dateSeparator;

            if (dateSepFormat == DateSeparatorFormat.Dashes)
            {
                dateSeparator = '-';
            }
            else // Slashes are the default.
            {
                dateSeparator = '/';
            }

            string monthFormatString;

            if (monthFormat == MonthFormat.ThreeLetters)
            {
                monthFormatString = "MMM";
            }
            else if (monthFormat == MonthFormat.FullMonth)
            {
                monthFormatString = "MMMM";
            }
            else // Number is the default.
            {
                monthFormatString = "MM";
            }

            string hourFormatString;
            string amPmFormatString;

            if (timeFormat == TimeFormat.Hour24)
            {
                hourFormatString = "HH";
                amPmFormatString = string.Empty;
            }
            else // 12 hour is the default.
            {
                hourFormatString = "hh";
                amPmFormatString = " tt";
            }

            string timeFormatString = $"{hourFormatString}:mm{amPmFormatString}";
            string formatString;

            if (dateFormat == DateFormat.DayMonthYear)
            {
                formatString = $"dd{dateSeparator}{monthFormatString}{dateSeparator}yyyy {timeFormatString}";
            }
            else if (dateFormat == DateFormat.YearMonthDay)
            {
                formatString = $"yyyy{dateSeparator}{monthFormatString}{dateSeparator}dd {timeFormatString}";
            }
            else // Month/Day/Year is the default.
            {
                formatString = $"{monthFormatString}{dateSeparator}dd{dateSeparator}yyyy {timeFormatString}";
            }

            return(date.ToString(formatString));
        }