Marklar
Marklar

Reputation: 1267

agendaDay row time format in fullCalendar

I am trying to set the time format in my calendar rows to appear as 1pm - 2pm, 2pm - 3pm, 3pm- 4pm, etc.

I have tried the following:

agenda: 'h:mm{ - h:mm}',
axisFormat: 'h:mm{ - h:mm}',  
day: 'h:mm{ - h:mm}', 
axisFormat: 'h(:mm)tt', 
timeFormat: {
    agenda: 'h:mm{ - h:mm}'
},

but none of the above, either alone or in combination seem to work for me.

I initialize my calendar as below:

  $('#calendar').fullCalendar({
    defaultView: 'agendaDay',
    allDaySlot: false,
    firstHour: 9,
    minTime: 9,
    maxTime: 19,
    selectable: true,
    unselectAuto: true,
    slotMinutes: 60,
    weekends: false,
    year: current_year,
    month: current_month,
    date: current_day,
    columnFormat: '',

Upvotes: 2

Views: 4189

Answers (1)

Regin Larsen
Regin Larsen

Reputation: 1152

FullCalendar does not provide a "to" time for the axisFormat and therefore the { - h:mm} part of you axisFormat is ignored.

And I don't think there's any way to do it without editing the FullCalendar source code.

But if you are feeling adventurous you could do the following changes in fullcalendar.js around line 3207:

    d = zeroDate();
    maxd = addMinutes(cloneDate(d), maxMinute);
    addMinutes(d, minMinute);

    // Add two lines
    var toD = cloneDate(d);
    addMinutes(toD, opt('slotMinutes'));

    slotCnt = 0;
    for (i=0; d < maxd; i++) {
        minutes = d.getMinutes();
        s +=
            "<tr class='fc-slot" + i + ' ' + (!minutes ? '' : 'fc-minor') + "'>" +
            "<th class='fc-agenda-axis " + headerClass + "'>" +

            // Changed line from "formatDate(d, opt('axisFormat')...)" to "formatDates(d, toD, opt('axisFormat')...)"
            ((!slotNormal || !minutes) ? formatDates(d, toD, opt('axisFormat')) : '&nbsp;') +

            "</th>" +
            "<td class='" + contentClass + "'>" +
            "<div style='position:relative'>&nbsp;</div>" +
            "</td>" +
            "</tr>";
        addMinutes(d, opt('slotMinutes'));

        // Add line
        addMinutes(toD, opt('slotMinutes'));

        slotCnt++;
    }

Upvotes: 4

Related Questions