I use the datetimepicker issued from that library : http://www.malot.fr/bootstrap-datetimepicker/
For my project i need to submit with GET form the picked date and time as an epoch format rounded at the next minute.
- At the moment the datetime picker send a correct epoch timestamp but it includes seconds depending on the moment the user clicks on the submit button.
i would like to avoid that.
I tried to round the linked field but it does not work, seconds still included in the timestamp.
Can you tell me how to get a clean and next minute rounded timestamp without any second ?
$('.form_datetime').datetimepicker({
language: 'fr',
pickerPosition: "bottom-left",
weekStart: 1,
startDate: new Date(), // remove dates in the past
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 0,
maxView: 3,
minuteStep: 1,
});
/* Addon : Hidden linked field returns epoch time - needs moment.js library */
/* get the datetimepicker controller */
let picker = $(`.form_datetime`).data(`datetimepicker`);
var coeff = 1000 * 60 * 1;
/* override its setValue() method */
let f = picker.setValue;
picker.setValue = function(...xs) {
/* call the original method first */
f.call(this, ...xs);
/* now set the linked field to epoch format */
/* Original code without rounding timestamp
$(`#${this.linkField}`).val(`${( this.getDate() || new Date() ) .getTime()}`);
*/
/* Trying to round timestamp to the next minutes (no second anymore) */
$(`#${this.linkField}`).val(`${( this.getDate() || new Date(Math.round(date.getTime() / coeff) * coeff) ) .getTime()}`);
};