Scheduler invalid date format, load from mongo

hi, I’m using scheduler.load("/user/data", json), but it gets invalid date and I can´t figure out why.
It only shows the events from parse.

html:

	<script src="https://cdn.dhtmlx.com/scheduler/edge/dhtmlxscheduler.js" charset="utf-8"></script>
	<link rel="stylesheet" href="https://cdn.dhtmlx.com/scheduler/edge/dhtmlxscheduler_material.css" type="text/css" charset="utf-8">

</head>
<body onload="init();">
<% include ../layouts/layout.ejs %>
	<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:80%;'>
		<div class="dhx_cal_navline">
			<div class="dhx_cal_prev_button">&nbsp;</div>
			<div class="dhx_cal_next_button">&nbsp;</div>
			<div class="dhx_cal_today_button"></div>
			<div class="dhx_cal_date"></div>
			<div class="dhx_cal_tab" name="day_tab"></div>
			<div class="dhx_cal_tab" name="week_tab"></div>
			<div class="dhx_cal_tab" name="month_tab"></div>
		</div>
		<div class="dhx_cal_header"></div>
		<div id = "ola_a" class="dhx_cal_data"></div>
	</div>
</body>
<script type="text/javascript">
	function init() {
		scheduler.config.xml_date = "%Y-%m-%d %H:%i";
		scheduler.config.first_hour = 8;
		scheduler.config.last_hour = 22;
		scheduler.config.dblclick_create = false;
		scheduler.config.draggable = false;
		scheduler.attachEvent("onTemplatesReady", function(){
			scheduler.templates.event_text=function(start,end,event){
				return "<b>" + event.text + "</b><br><i>" + event.type + "</b><br><i>" + event.location + "</i>";
			}
		});
		scheduler.init("scheduler_here", new Date(2018, 9, 4), "week");
		scheduler.parse([
			{type:"PL", location: "1.2.21", text:"ITW",    start_date:"2018/09/10 14:00", end_date:"2018/09/10 17:00"},
			{type:"T", location: "3.1.14", text:"P-II",    start_date:"2018/09/11 14:00", end_date:"2018/09/11 17:00"},
			{type:"PL", location: "1.2.25", text:"BD",    start_date:"2018/09/11 16:00", end_date:"2018/09/11 19:00"}
		],"json");
            scheduler.load("/user/data","json");
	}
</script>

server side:

router.get('/horario', function (req, res) {
    var e = new Data();
    e.text = "BB";
    e.start_date = new Date(2018,8,4, 10, 0);
    e.end_date = new Date(2018,8,4, 12, 0);
    e.save();
    res.render('user/horario');
});
router.get('/data', function(req, res){
    Data.find({text: "BB"}).exec(function(err,data){
        for (var i = 0; i < data.length; i++) {
            data[i].id = data[i]._id;
            console.log(data[i].id);
        }
        //output response
        res.send(data);
    });
});

Hi,

You need to set the date format in the xml_date config according to the format in data:

hi Guys ,

Actually i have implement the “configuration.xmldate” logic used to show the event using calendar . but its not supported some date format. My plugin version 4.4.9

for example

start date :01.01.2019
end Date :05.02.2019

I am getting the result in UI like this (01.01.2019 -30.01.2019).

can you please share the solutions to me .

Hello,

you can try redefining functions that parse input strings into the dates that are used by the scheduler:

scheduler.attachEvent("onTemplatesReady", function(){
   var dateFormat = "%d.%m.%Y";
   var strToDate = scheduler.date.str_to_date(dateFormat);
   var dateToStr = scheduler.date.date_to_str(dateFormat);
 
   scheduler.templates.xml_date = function(dateString){
      return strToDate(dateString);
   };
   scheduler.templates.xml_format = function(date){
      return dateToStr(date);
   };
});

There you’ll have complete control over how dates are processed, so if you have a format that can’t be parsed by our scheduler.date helper, you’ll be able to parse such dates by your custom code