This is a migrated thread and some comments may be shown as answers.

Custom Interval Formatters

11 Answers 219 Views
TimeBar
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 16 Jan 2012, 08:55 AM
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.

11 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 18 Jan 2012, 03:49 PM
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 >>

0
David
Top achievements
Rank 2
answered on 18 Jan 2012, 04:16 PM
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.
0
Tsvetie
Telerik team
answered on 20 Jan 2012, 10:53 AM
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 >>

0
David
Top achievements
Rank 2
answered on 20 Jan 2012, 11:19 AM
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.
0
Tsvetie
Telerik team
answered on 23 Jan 2012, 10:37 AM
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 >>

0
Jaspreet
Top achievements
Rank 1
answered on 18 Feb 2013, 01:12 PM
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.
0
Tsvetie
Telerik team
answered on 19 Feb 2013, 09:17 AM
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.

0
Jaspreet
Top achievements
Rank 1
answered on 19 Feb 2013, 11:10 AM
Hi Tsvetie,

Thank you for the reply. Waiting for the release.
0
John Tobin
Top achievements
Rank 1
answered on 03 Mar 2013, 12:25 PM
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.
0
Tsvetie
Telerik team
answered on 05 Mar 2013, 04:08 PM
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.

0
John Tobin
Top achievements
Rank 1
answered on 05 Mar 2013, 05:31 PM
Actually I have put 'CultureInfo.CurrentCulture' but have to put 'CultureInfo.InvariantCulture'.
Working fine now.

Thank you for your help.


Tags
TimeBar
Asked by
David
Top achievements
Rank 2
Answers by
Tsvetie
Telerik team
David
Top achievements
Rank 2
Jaspreet
Top achievements
Rank 1
John Tobin
Top achievements
Rank 1
Share this question
or