Zaraki Kenpachi
Zaraki Kenpachi

Reputation: 5730

FullCalendar v4 compare event date

i have problem with comparing two dates for FullCalendar v4:

First i set today date:

var today_a = new Date().toISOString().slice(0, 10);

next i try co compare this date with event start date [collected from Django view] using template language, to change its color, like this:

events: [
    {% for event in main_events %}
        {
            color: {% if sub_event.start_date|date:"Y-m-d" < today_a %}'green'{%else%}'SkyBlue'{%endif%},
        },
    {% endfor %}
],

That is not working but if i set static date instead of today_a then all is working as expected:

color: {% if sub_event.start_date|date:"Y-m-d" < '2019-10-30' %}'green'{%else%}'SkyBlue'{%endif%},

Variable today_a is a string. How to put this variable for compare to work?

Upvotes: 0

Views: 97

Answers (1)

Zaraki Kenpachi
Zaraki Kenpachi

Reputation: 5730

Thanks to ADyson sugestions i have managed this by using eventRender:

  eventRender: function(info) {
       if (info.event.start.toISOString().slice(0, 10) < today_a) {
         info.el.style.backgroundImage = 'linear-gradient(to right, red, yellow)';
       }

Thank You All for help :)

Upvotes: 1

Related Questions