search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How do I adjust the header row time format in the Scheduler?

Asked by Scott Mitchell
11 years ago.

I am using the ASP.NET MVC Scheduler to show one day's worth of scheduled activities where each column represents a block of time of 15 minutes. Here is my configuration:

@Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig
{
...
StartDate = ...,
Days = 1,
CellDuration = 15,
CellGroupBy = GroupBy.Hour,
TimeFormat = DayPilot.Web.Mvc.Enums.TimeFormat.Clock12Hours,
})

Along the very top I see the hours of the day, from 0 to 23, and beneath that there are 15 minute increments: 00, 15, 30, then 45.

In the topmost bar, however, I'd like to show the time as 12 AM, 1 AM, 2AM, ... 12 PM, 1 PM, ... 11 PM, rather than 0-23.

How do I go about doing this?

Thanks!

Answer posted by Dan Letecky [DayPilot]
11 years ago.

You can customize the header strings by overriding OnBeforeTimeHeader method. Just set e.InnerHtml as needed:

            protected override void OnBeforeTimeHeaderRender(BeforeTimeHeaderRenderArgs e)
            {
                if (e.IsColGroup)
                {
                    e.InnerHtml = TimeFormatter.GetHour(e.Start, TimeFormat.Clock12Hours, null);
                }
            }

In this case, it should be also possible to change the time format using TimeFormat property in the config:

TimeFormat = TimeFormat.Clock12Hours

The default value of TimeFormat is Auto. It detects the time format from the current culture. This way:

        public static TimeFormat DetectTimeFormat(TimeFormat input)
        {
            if (input == TimeFormat.Auto)
            {
                if (Thread.CurrentThread.CurrentCulture.DateTimeFormat.AMDesignator == "AM")
                {
                    return TimeFormat.Clock12Hours;
                }
                else
                {
                    return TimeFormat.Clock24Hours;
                }
            }
            else
            {
                return input;
            }
        }

Comment posted by Scott Mitchell
11 years ago.

Dan, using the OnBeforeTimeHeaderRender code you posted worked, thanks.

FWIW, I did (and still do!) have the following configuration in the scheduler:

TimeFormat = DayPilot.Web.Mvc.Enums.TimeFormat.Clock12Hours

However, the 12 hour display only appears if I use the code you shared for OnBeforeTimeHeaderRender. (If I comment it out, even with specifying the TimeFormat in my view, the time header goes back to 0..23.)

Thanks

Comment posted by DG
10 years ago.

Specifying the timeformat in the config does not work alone. We have to do it in the OnBeforeTimeHeaderRender. Is it a bug or just the right way to do it?

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.