Fix js bug.

This commit is contained in:
BoHung Chiu 2022-07-13 15:58:31 +08:00
parent 659c6b21fd
commit 31f2ed3a71
4 changed files with 37 additions and 13 deletions

View File

@ -44,6 +44,7 @@ if(window.calendar_variable.date_type == 2){
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
} }
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.std_date_format = 'y-MM-d';

View File

@ -44,6 +44,7 @@ if(window.calendar_variable.date_type == 2){
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
} }
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.std_date_format = 'y-MM-d';

View File

@ -43,6 +43,7 @@ if(window.calendar_variable.date_type == 2){
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
} }
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.std_date_format = 'y-MM-d';
@ -150,9 +151,12 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
}) })
return '#'+comp return '#'+comp
} }
var format_date = function(date){ var format_date = function(date, numeric){
date = new Date(date); date = new Date(date);
return getDateString(date, window.calendar_variable.date_format); if(numeric)
return getDateString(date, window.calendar_variable.date_format_numeric);
else
return getDateString(date, window.calendar_variable.date_format);
} }
var format_datetime = function(date){ var format_datetime = function(date){
date = new Date(date); date = new Date(date);
@ -394,6 +398,11 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
prevMonthFunc(toggle_data) prevMonthFunc(toggle_data)
} }
} }
var get_start_of_date = function(date){
var tmp_date = new Date(date);
tmp_date.setHours(0,0,0,0);
return tmp_date;
}
var fetchEvents = function(){ var fetchEvents = function(){
var usd = Math.round(firstDay/1000), var usd = Math.round(firstDay/1000),
usd_target = Math.round(first_target_day/1000), usd_target = Math.round(first_target_day/1000),
@ -409,10 +418,12 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
$.each(data.events,function(index,eve){ $.each(data.events,function(index,eve){
var sd = new Date(eve.start), var sd = new Date(eve.start),
ed = new Date(eve.end), ed = new Date(eve.end),
sd_date = new Date(format_date(eve.start)), sd_date = new Date(format_date(eve.start, true)),
ed_date = new Date(format_date(eve.end)), ed_date = new Date(format_date(eve.end, true)),
timeDiff = ed_date.getTime() - sd_date.getTime(), start_of_sd_date = get_start_of_date(sd_date),
dayDiff = Math.round(timeDiff / (1000 * 3600 * 24)); start_of_ed_date = get_start_of_date(ed_date),
timeDiff = start_of_ed_date.getTime() - start_of_sd_date.getTime(),
dayDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(eve.allDay && dayDiff < 1){ if(eve.allDay && dayDiff < 1){
dayDiff = 1 dayDiff = 1
} }

View File

@ -43,6 +43,7 @@ if(window.calendar_variable.date_type == 2){
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
} }
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.std_date_format = 'y-MM-d';
@ -173,9 +174,12 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
}) })
return '#'+comp return '#'+comp
} }
var format_date = function(date){ var format_date = function(date, numeric){
date = new Date(date); date = new Date(date);
return getDateString(date, window.calendar_variable.date_format); if(numeric)
return getDateString(date, window.calendar_variable.date_format_numeric);
else
return getDateString(date, window.calendar_variable.date_format);
} }
var format_datetime = function(date){ var format_datetime = function(date){
date = new Date(date) date = new Date(date)
@ -534,6 +538,11 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
prevMonthFunc(toggle_data) prevMonthFunc(toggle_data)
} }
} }
var get_start_of_date = function(date){
var tmp_date = new Date(date);
tmp_date.setHours(0,0,0,0);
return tmp_date;
}
var fetchEvents = function(){ var fetchEvents = function(){
var usd = Math.round(firstDay/1000), var usd = Math.round(firstDay/1000),
usd_target = Math.round(first_target_day/1000), usd_target = Math.round(first_target_day/1000),
@ -549,16 +558,18 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
$.each(data.events,function(index,eve){ $.each(data.events,function(index,eve){
var sd = new Date(eve.start), var sd = new Date(eve.start),
ed = new Date(eve.end), ed = new Date(eve.end),
sd_date = new Date(format_date(eve.start)), sd_date = new Date(format_date(eve.start, true)),
ed_date = new Date(format_date(eve.end)), ed_date = new Date(format_date(eve.end, true)),
timeDiff = ed_date.getTime() - sd_date.getTime(), start_of_sd_date = get_start_of_date(sd_date),
dayDiff = Math.round(timeDiff / (1000 * 3600 * 24)); start_of_ed_date = get_start_of_date(ed_date),
timeDiff = start_of_ed_date.getTime() - start_of_sd_date.getTime(),
dayDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(eve.allDay && dayDiff < 1){ if(eve.allDay && dayDiff < 1){
dayDiff = 1 dayDiff = 1
} }
if(dayDiff > 0){ if(dayDiff > 0){
var inserting_date = sd.getDate(); var inserting_date = sd.getDate();
for(var i = 0;i < dayDiff; i++){ for(var i = 0;i <= dayDiff; i++){
var dt = inserting_date + "-" + sd.getMonth() + "-" + sd.getFullYear(), var dt = inserting_date + "-" + sd.getMonth() + "-" + sd.getFullYear(),
td = dom.find("td[data-date-node=" + dt + "]"); td = dom.find("td[data-date-node=" + dt + "]");
if (events[dt]==undefined){ if (events[dt]==undefined){