When i make an appointment on the calendar, the start and end time are showing correctly , but after i reload the page, i got a different datetime on the calendar and inside the database .
So for example, if i made an appointment from 09:00 AM to 10:30 AM, inside database i got this :
Start : 2017-04-30 15:00:00
End : 2017-04-30 16:30:00
My view.py :
appointment = Appointment()
appointment.start_time = parse_appoitment(start)
appointment.end_time = parse_appoitment(end)
appointment.note = data
appointment.user_id = abonent.id
appointment.client_id = client.id
db.session.add(appointment)
db.session.commit()
and also the date parser :
def parse_appoitment(time):
start_datime = str(time)[0:25]
date = parse(start_datime)
return date.strftime('%Y-%m-%d %H:%M:%S')
Here is the javascript
code:
{% if client.is_subscriber(master.id) %}
$(document).ready(function() {
var initialLocaleCode = 'ru';
var d = new Date();
var strDate = d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
defaultDate: moment(),
// month basicWeek basicDay agendaWeek agendaDay listYear listMonth listWeek listDay
defaultView: 'agendaWeek',
height: 650,
locale: initialLocaleCode,
local: 'GMT+06:00',
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectHelper: true,
select: function(start, end) {
if(start.isBefore(moment())) {
$('#calendar').fullCalendar('unselect');
return false;
} else {
$(this).css({"cursor":"pointer"});
}
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
// console.log(eventData);
$.ajax({
type: 'POST',
url: '{{url_for("client.get_appo", abonent=master.slug)}}',
// contentType: 'application/json;charset=UTF-8',
data: {
'title': title,
'start': eventData['start']['_d'],
'end': eventData['end']['_d']
}
})
.done(function(data){
if(data.error){
// console.log(data.data);
console.log(eventData['start']['_d']);
}
else {
// console.log(data.data);
console.log(eventData['start']['_d']);
}
});
}
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{% for appo in master.appointments %}
{% if appo.is_not_accepted %}
{% endif %}
{
"title": "{{appo.note}}",
"start": "{{appo.start_time}}",
"end": "{{appo.end_time}}"
},
{% endfor %}
]
});
// build the locale selector's options
$.each($.fullCalendar.locales, function(localeCode) {
$('#locale-selector').append(
$('<option/>')
.attr('value', localeCode)
.prop('selected', localeCode == initialLocaleCode)
.text(localeCode)
);
});
// when the selected option changes, dynamically change the calendar option
$('#locale-selector').on('change', function() {
if (this.value) {
$('#calendar').fullCalendar('option', 'locale', this.value);
$(this).css({'background-color':'red'});
}
});
});
{% endif %}
Am not sure by this local: 'GMT+06:00',
, weither added it or not the same thing i got every time.
Edit:
I forgot to type the format that i got after submitting an appointment and before i parse it:
Sun Apr 23 2017 15:30:00 GMT+0600 (+06)
to Sun Apr 23 2017 17:00:00 GMT+0600 (+06)
Here i made one from 09:30 to 11:00, but i got the above result .
You must set timezone to local inside your settings as following:
timezone: 'local'
Now it works :) .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.