Custom Interval Formatters

12 posts, 0 answers
  1. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 16 Jan 2012 Link to this post

    Hi,

    Summary:
    How can I customize the interval formatter for hours to display 24-hour time?

    Background:
    I've found the default interval formatters detailed here:
    http://www.telerik.com/help/wpf/radtimebar-intervals-formatters.html

    I have my Windows regional settings set to 24-hour time (without any suffix) and what I'm finding is that the hour interval for the RadTimeBar is displaying in 12-hour time, however without any suffix, presumably because Windows regional settings do not specify a suffix when set to displaying 24-hour time. This makes it a little more ambiguous for the user who is expecting 24-hour time, however gets 12-hour time instead.

    How can I customize the interval formatter for hours to display 24-hour time?

    Kind regards,
    Dave.
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 18 Jan 2012 Link to this post

    Hello Dave,

    As mentioned in our online documentation, the HourInterval supports the following datetime formats:
    • hh tt
    • ht
    Currently, you cannot specify the datetime formats that an interval uses and the only way to change these, is to change the formats collection in the code of RadTimeBar. You need to use the H format specifier in this case.

    All the best,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 18 Jan 2012 Link to this post

    Hi Tsvetie,

    You stated:
    "the only way to change these, is to change the formats collection in the code of RadTimeBar."

    Can you show me how to do that with a working example?

    Kind regards,
    Dave.
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 20 Jan 2012 Link to this post

    Hi Dave,

    What I meant by that, is that RadTimeBar does not support changing the formats of the intervals and that the only way to do it, is to modify the source code. Thit means that you have to download the source code, make the modifications that you need to the interval classes (e.g. the HourInterval class), build a custom DLL and use it in your solution. Unfortunately, only licensed customers can download the source code of our controls.

    Please note that we do not offer custom solutions to clients and we do not support custom modifications of the code.

    Kind regards,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 20 Jan 2012 Link to this post

    Hi Tsvetie,

    Can you please forward a request to the development team to include public access to the interval formatters collection so that can be modified without requiring modifying Telerik's source code? From my personal perspective, I believe the ability to choose between 12-hour or 24-hour formatting for hours would be a useful addition to many developers as 24-hour formatting is not an uncommon setting.

    Kind regards,
    Dave.
  7. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 23 Jan 2012 Link to this post

    Hi Dave,

    This request is already logged in our database. Here is a link to out PITS system, where you can vote and track the progress on the feature.

    Greetings,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Jaspreet
    Jaspreet avatar
    2 posts
    Member since:
    Feb 2013

    Posted 18 Feb 2013 Link to this post

    I have exactly the same issue.
    I am testing timebar to fit my scenario where I need relative time in the timebar rather than absolute time with the lowest time interval used will be seconds and next will be minutes. This is going to be relative time so I donot want timeofday or date to be displayed, just seconds  and minutes. The link of PITS that you mentioned, shows the issue as resolved but I am not able to find any documentation of how to achieve this. I have also tried to create my own interval using the abstract class "Interval Base", but I am having no luck on that as well because of missing documentation. Is it possible in Q2 2012 sp2 release. I need some pointers please.
  9. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 19 Feb 2013 Link to this post

    Hi Jaspreet,

    The feature will be available with Q1 2013, scheduled for later this week. In terms of API, there will be a new property for the predefined intervals - FormatterProvider of type IIntervalFormatterProvider. In order to specify custom formatters for an interval, you need to create your custom class that implements IIntervalFormatterProvider. For example:
    public class MonthFormatterProvider : IIntervalFormatterProvider
    {
        public Func<DateTime, string>[] GetFormatters(IntervalBase interval)
        {
            return new Func<DateTime, string>[]
                {
                    date => date.ToString("MMM")
                };
        }
     
        public Func<DateTime, string>[] GetIntervalSpanFormatters(IntervalBase interval)
        {
            return new Func<DateTime, string>[]
                {
                    date => String.Format("{0} ... {1}", date.ToString("MMM").Substring(0, 1), interval.IncrementByCurrentInterval(date).ToString("MMM").Substring(0, 1))
                };
        }
    }

     

    Greetings,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Jaspreet
    Jaspreet avatar
    2 posts
    Member since:
    Feb 2013

    Posted 19 Feb 2013 Link to this post

    Hi Tsvetie,

    Thank you for the reply. Waiting for the release.
  11. John Tobin
    John Tobin avatar
    16 posts
    Member since:
    Mar 2008

    Posted 03 Mar 2013 Link to this post

    Hello Telerik,

    I am trying to set up IIntervalFormatterProvider like your example.
    But I have a problem with AM/PM format.

    My format is like 'd MMM, hh tt', but it will be shown only 'd MMM, hh'.
    We are using Silverlight Q1 2013 and the rest of formula is exactly same as the example.

    Could you please advise me if it is a bug or I did something wrong?

    Thanks.
  12. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 05 Mar 2013 Link to this post

    Hello Michael Gannon,

    The "tt" custom format specifier depends on the current culture. You can get this result in case you are using a culture, in which the localized designator is an empty string. You can read more about this in MSDN.

    Regards,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  13. John Tobin
    John Tobin avatar
    16 posts
    Member since:
    Mar 2008

    Posted 05 Mar 2013 Link to this post

    Actually I have put 'CultureInfo.CurrentCulture' but have to put 'CultureInfo.InvariantCulture'.
    Working fine now.

    Thank you for your help.


Back to Top
UI for WPF is Visual Studio 2017 Ready