Example #1
0
        /// <summary>
        /// Gets the time from a
        /// <see cref="T:System.DateTime"/>
        /// object in short Metro format.
        /// </summary>
        /// <remarks>
        /// Metro design guidelines normalize strings to lowercase.
        /// </remarks>
        /// <param name="dt">Time information.</param>
        /// <returns>"10:20p" for 10:20 p.m. when en-US.</returns>
        public static string GetSuperShortTime(DateTime dt)
        {
            if (formatInfo_GetSuperShortTime == null)
            {
                lock (lock_GetSuperShortTime)
                {
                    StringBuilder result = new StringBuilder(string.Empty);
                    string        seconds;

                    formatInfo_GetSuperShortTime = (DateTimeFormatInfo)CultureInfo.CurrentCulture.DateTimeFormat.Clone();

                    result.Append(formatInfo_GetSuperShortTime.LongTimePattern);
                    seconds = rxSeconds.Match(result.ToString()).Value;
                    result.Replace(" ", string.Empty);
                    result.Replace(seconds, string.Empty);
                    if (!(DateTimeFormatHelper.IsCurrentCultureJapanese() ||
                          DateTimeFormatHelper.IsCurrentCultureKorean() ||
                          DateTimeFormatHelper.IsCurrentCultureHungarian()))
                    {
                        result.Replace(DoubleMeridiemDesignator, DoubleMeridiemDesignator);
                    }

                    formatInfo_GetSuperShortTime.ShortTimePattern = result.ToString();
                }
            }

            return(dt.ToString("t", formatInfo_GetSuperShortTime).ToLowerInvariant());
        }
Example #2
0
        /// <summary>
        /// Converts a
        /// <see cref="T:System.DateTime"/>
        /// object into a string appropriately formatted for threads.
        /// This format can be found in messaging.
        /// </summary>
        /// <remarks>
        /// This format never displays the year.
        /// </remarks>
        /// <param name="value">The given date and time.</param>
        /// <param name="targetType">
        /// The type corresponding to the binding property, which must be of
        /// <see cref="T:System.String"/>.
        /// </param>
        /// <param name="parameter">(Not used).</param>
        /// <param name="culture">(Not used).</param>
        /// <returns>The given date and time as a string.</returns>



        public object Convert(object value, Type targetType, object parameter, string language)
        {
            // Target value must be a System.DateTime object.


            string result;

            DateTime given = (DateTime)value;

            DateTime current = DateTime.Now;

            if (DateTimeFormatHelper.IsFutureDateTime(current, given))
            {
                // Future dates and times are not supported.
                throw new NotSupportedException();
            }

            if (DateTimeFormatHelper.IsAnOlderWeek(current, given))
            {
                result = DateTimeFormatHelper.GetMonthAndDay(given);
            }
            else if (DateTimeFormatHelper.IsPastDayOfWeekWithWindow(current, given))
            {
                result = DateTimeFormatHelper.GetAbbreviatedDay(given);
            }
            else
            {
                // Given day time is today.
                result = DateTimeFormatHelper.GetSuperShortTime(given);
            }

            return(result);
        }
Example #3
0
 /// <summary>
 /// Gets the abbreviated day from a
 /// <see cref="T:System.DateTime"/>
 /// object.
 /// </summary>
 /// <param name="dt">Date information.</param>
 /// <returns>e.g. "Mon" for Monday when en-US.</returns>
 public static string GetAbbreviatedDay(DateTime dt)
 {
     if (DateTimeFormatHelper.IsCurrentCultureJapanese() || DateTimeFormatHelper.IsCurrentCultureKorean())
     {
         return("(" + dt.ToString("ddd", CultureInfo.CurrentCulture) + ")");
     }
     else
     {
         return(dt.ToString("ddd", CultureInfo.CurrentCulture));
     }
 }
        /// <summary>
        /// Converts a
        /// <see cref="T:System.DateTime"/>
        /// object into a string appropriately formatted for hourly feeds.
        /// This format can be found in messaging.
        /// </summary>
        /// <param name="value">The given date and time.</param>
        /// <param name="targetType">
        /// The type corresponding to the binding property, which must be of
        /// <see cref="T:System.String"/>.
        /// </param>
        /// <param name="parameter">(Not used).</param>
        /// <param name="culture">(Not used).</param>
        /// <returns>The given date and time as a string.</returns>


        public object Convert(object value, Type targetType, object parameter, string language)
        {
            // Target value must be a System.DateTime object.
            if (!(value is DateTime))
            {
                throw new ArgumentException();
            }

            StringBuilder result = new StringBuilder(string.Empty);

            DateTime given = (DateTime)value;

            DateTime current = DateTime.Now;

            if (DateTimeFormatHelper.IsFutureDateTime(current, given))
            {
                // Future dates and times are not supported.
                throw new NotSupportedException();
            }

            if (DateTimeFormatHelper.IsAnOlderYear(current, given))
            {
                result.AppendFormat(CultureInfo.CurrentCulture, "{0}, {1}",
                                    DateTimeFormatHelper.GetShortDate(given),
                                    DateTimeFormatHelper.GetSuperShortTime(given));
            }
            else if (DateTimeFormatHelper.IsAnOlderWeek(current, given))
            {
                result.AppendFormat(CultureInfo.CurrentCulture, "{0}, {1}",
                                    DateTimeFormatHelper.GetMonthAndDay(given),
                                    DateTimeFormatHelper.GetSuperShortTime(given));
            }
            else if (DateTimeFormatHelper.IsPastDayOfWeekWithWindow(current, given))
            {
                result.AppendFormat(CultureInfo.CurrentCulture, "{0}, {1}",
                                    DateTimeFormatHelper.GetAbbreviatedDay(given),
                                    DateTimeFormatHelper.GetSuperShortTime(given));
            }
            else
            {
                // Given day time is today.
                result.Append(DateTimeFormatHelper.GetSuperShortTime(given));
            }

            if (DateTimeFormatHelper.IsCurrentUICultureFrench())
            {
                result.Replace(",", string.Empty);
            }

            return(result.ToString());
        }