YAFLogo

midwestSS
  • midwestSS
  • 100% (Exalted)
  • YAF MVP Topic Starter
14 years ago
in the shoutbox, how to change it from saying

Friday, October21 2009, 4:54pm MidwestSS:

to just 4:54pm MidwestSS:

?

Sponsor
chriscoe71
14 years ago

in the shoutbox, how to change it from saying

Friday, October21 2009, 4:54pm MidwestSS:

to just 4:54pm MidwestSS:

?

midwestSS wrote:

I'm not sure if this is the easiest or the cleanest way, but you could, assuming you are working off the entire code base, add another method to Yaf.Classes.Core > Services > YafDateTime.cs and call it from /Controls/ShoutBox.ascx

The method could look something like:

        /// <summary>
    /// Formats a datetime value into time only 5:25 PM
    /// </summary>
    /// <param name="o">
    /// This formats the date.
    /// </param>
    /// <returns>
    /// Short formatted date.
    /// </returns>
    public string FormatTimeOnly(object o)
    {
        DateTime dt = (DateTime)o + TimeOffset;
        try
        {
            if (YafContext.Current.BoardSettings.DateFormatFromLanguage)
            {
                return YafContext.Current.Localization.FormatDateTime(YafContext.Current.Localization.GetText("FORMAT_TIME_ONLY"), dt);
            }
            else
            {
                return String.Format("{0:h:mm tt}", dt);
            }
        }
        catch (Exception)
        {
            return dt.ToString("h:mm tt");
        }
    }

Recompile the code.

Then, on line 58 of /Controls/ShoutBox.ascx change YafServices.DateTime.FormatDateTimeTopic to YafServices.DateTime.FormatTimeOnly

To account for date formats being chosen from the language file, you would also need to add

<Resource tag="FORMAT_TIME_ONLY">h:mm tt</Resource>
to the language.xml file under the "COMMON" page.
Kamyar
  • Kamyar
  • 100% (Exalted)
  • YAF Developer
14 years ago
In Controls/Shoutbox.ascx:

Replace this:

<i><asp:Label ID="dateLabel" runat="server" Text='<%# YafServices.DateTime.FormatDateTimeTopic( ((System.Data.DataRowView)Container.DataItem)["Date"] ) %>' /></i>

With this:

<i><asp:Label ID="dateLabel" runat="server" Text='<%# YafServices.DateTime.FormatTime( Convert.ToDateTime(((System.Data.DataRowView)Container.DataItem)["Date"])) %>' /></i>

Although it's not exactly what you want (Shows seconds) but if that's not a big deal for you then it's an easy way.


If at first you don’t succeed, call it version 1.0
chriscoe71
14 years ago
Kamyar's way requires a lot less coding.

The method I put up removed the seconds from the display.