fixed parseInt problems (issue 688)

This commit is contained in:
Adam Shaw 2011-01-01 13:39:30 -08:00
parent 679b9e48d6
commit 09427f27cf
2 changed files with 98 additions and 4 deletions

View file

@ -147,7 +147,7 @@ function parseDate(s, ignoreTimezone) { // ignoreTimezone defaults to true
} }
if (typeof s == 'string') { if (typeof s == 'string') {
if (s.match(/^\d+$/)) { // a UNIX timestamp if (s.match(/^\d+$/)) { // a UNIX timestamp
return new Date(parseInt(s) * 1000); return new Date(parseInt(s, 10) * 1000);
} }
if (ignoreTimezone === undefined) { if (ignoreTimezone === undefined) {
ignoreTimezone = true; ignoreTimezone = true;
@ -220,14 +220,14 @@ function parseTime(s) { // returns minutes since start of day
} }
var m = s.match(/(\d+)(?::(\d+))?\s*(\w+)?/); var m = s.match(/(\d+)(?::(\d+))?\s*(\w+)?/);
if (m) { if (m) {
var h = parseInt(m[1]); var h = parseInt(m[1], 10);
if (m[3]) { if (m[3]) {
h %= 12; h %= 12;
if (m[3].toLowerCase().charAt(0) == 'p') { if (m[3].toLowerCase().charAt(0) == 'p') {
h += 12; h += 12;
} }
} }
return h * 60 + (m[2] ? parseInt(m[2]) : 0); return h * 60 + (m[2] ? parseInt(m[2], 10) : 0);
} }
} }
@ -271,7 +271,7 @@ function formatDates(date1, date2, format, options) {
for (i2=i+1; i2<len; i2++) { for (i2=i+1; i2<len; i2++) {
if (format.charAt(i2) == ')') { if (format.charAt(i2) == ')') {
var subres = formatDate(date, format.substring(i+1, i2), options); var subres = formatDate(date, format.substring(i+1, i2), options);
if (parseInt(subres.replace(/\D/, ''))) { if (parseInt(subres.replace(/\D/, ''), 10)) {
res += subres; res += subres;
} }
i = i2; i = i2;

View file

@ -0,0 +1,94 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
defaultView: 'agendaWeek',
minTime: '09:30',
maxTime: '15:30',
editable: true,
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1)
},
{
title: 'Long Event',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2)
},
{
id: 999,
title: 'Repeating Event',
start: new Date(y, m, d-3, 16, 0),
allDay: false
},
{
id: 999,
title: 'Repeating Event',
start: new Date(y, m, d+4, 16, 0),
allDay: false
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 5),
end: new Date(y, m, d, 14, 43),
allDay: false
},
{
title: 'Birthday Party',
start: new Date(y, m, d+1, 19, 0),
end: new Date(y, m, d+1, 22, 30),
allDay: false
},
{
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/'
}
]
});
});
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>