Reputation: 540
I'm having a problem trying to display events on FullCalendar. Some events are displayed and others not.
I fill the FC via JSON and until now was working well even with the pagination to only retrieve the events of the selected month.
...
events: {
url: '/getEvents',
method: 'GET',
failure: function(error) {
console.log(error);
alerta("Error", "Ups...", "red");
},
},
...
But now I'm trying to add more events from other stuff stored on the DB and, despite construct them on the same way, they are not shown on the calendar.
I construct the events like this (I've sanitized the code):
rows = connection.execute("SELECT...........")
events = []
for row in rows:
event = {"id": row['id'], "title": row['title'], "start": row['start'], "end": row['end'], "allDay": row['allDay'], "url": row['url'], "color": row['color'], "extendedProps": {"company": row['company'], "state": fila['state']}}
if row['groupId'] is not None:
event['groupId'] = str(row['groupId'])
events.append(event)
Now, on other part of the program I create events in a similar way:
more_rows = connection.execute("SELECT....")
more_events = []
for row in more_rows:
event = {"id": row['id'], "title": row['title'], "start": row['start'], "end": row['end'], "allDay": 1, "url": "", "color": row['color'], "extendedProps": {"company": row['company'], "description": row['description'], "type": row['type'], "tecnology": row['tecnology'], "state": row['state']}}
more_events.append(event)
They are sent together to the browser:
...
events.extend(more_events)
return jsonify(events), 200
...
The jsonify(events)
sends to the browser this JSON (I use double quotes on python code, but jsonify replaces it to single quotes):
[{'allDay': 1, 'color': 'blue', 'end': '2019-10-24T00:00:00.000Z', 'extendedProps': {'company': 'Company test', 'state': 'Active'}, 'groupId': '48', 'id': 27, 'start': '2019-10-23T00:00:00.000Z', 'title': 'A title', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-10-11T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'oapisdvañklsjdhalksjdflaksjdf', 'state': 'Active', 'tecnology': 'javascript+html', 'type': 'Cool'}, 'id': 74, 'start': '2019-10-07T00:00:00.00.000Z', 'title': 'owqsakjdflh', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-10-23T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'sdgsdfgwertwertwg', 'state': 'Active', 'tecnology': 'c', 'type': 'Cool'}, 'id': 75, 'start': '2019-10-21T00:00:00.00.000Z', 'title': '1eqwrwqer', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-11-07T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'asdfafasdfasdfasdf', 'state': 'Active', 'tecnology': 'java', 'type': 'Cool'}, 'id': 76, 'start': '2019-11-04T00:00:00.00.000Z', 'title': 'Bla bla bla', 'url': ''}]
The thing is... the first element it's printed as an event but the rest of elements on the JSON are not printed.
I can't see where is my mistake or what I'm doing wrong.
Regards.
Upvotes: 0
Views: 92
Reputation: 540
I found the problem (well, actually a co-worker) and it's here:
First element: 'end':'2019-10-24T00:00:00.000Z'
|| 'start':'2019-10-23T00:00:00.000Z'
The other elements: 'end': '2019-10-23T00:00:00.00.000Z'
|| 'start': '2019-10-21T00:00:00.00.000Z'
The thing is: 2019-10-24T00:00:00.000Z and 2019-10-23T00:00:00.00.000Z
I use this SQL to compare the dates (they are not stored on ISO 8601):
SELECT id, ....., strftime('%Y-%m-%dT%H:%M:%fZ', start_date) AS start, strftime('%Y-%m-%dT%H:%M:%fZ', end_date) AS end, ......
FROM table
WHERE state = 'Active' AND start > '....' AND end < '....'
My problem was supose that SQlite strftime it's equal to PYTHON strftime, but nope.
I was using this (Python): '%Y-%m-%dT%H:%M:%S.%fZ' instead of this (SQlite): '%Y-%m-%dT%H:%M:%fZ'
%S Second as a zero-padded decimal number.
%f Microsecond as a decimal number, zero-padded on the left.
%S seconds: 00-59
%f fractional seconds: SS.SSS
So be carefull and do not confuse the python format with the sqlite format.
Regards!
Upvotes: 1