Why does Safari/Opera not work with this javascript code?
Posted
by robinjfisher
on Stack Overflow
See other posts from Stack Overflow
or by robinjfisher
Published on 2010-04-24T17:57:55Z
Indexed on
2010/04/24
18:03 UTC
Read the original article
Hit count: 331
Hi,
I am working on a calendar that will show bookings. The height of containing the booking is calculated dynamically in proportion to the length of the booking. The following code works perfectly well in Firefox but not in Safari or Opera:
function calculateBookingHeight(from, to) {
var today = new Date;
var end = new Date.UTC(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDate(),23);
var start = new Date.UTC(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDate(),6);
var from = new Date(from);
var to = new Date(to);
if (from > start && to < end) {
var difference = (to - from) / 120000;
} else if (from > start && to > end) {
var difference = (end - from) / 120000;
} else {
var difference = 510
}
return difference;
}
In summary, each hour on the calendar is a height of 30px. The second if statement deals with the end of the booking being the following day.
If I replace the entire code block with return 510
, Safari behaves as expected and sets the height of each booking to 510px so I assume it must be something in this function that is causing the problem.
Any help would be appreciated.
Thanks
Robin
© Stack Overflow or respective owner