@@ 11322-11341 (lines=20) @@ | ||
11319 | } |
|
11320 | }; |
|
11321 | ||
11322 | dc.utils.subtract = function (l, r) { |
|
11323 | if (typeof r === 'string') { |
|
11324 | r = r.replace('%', ''); |
|
11325 | } |
|
11326 | ||
11327 | if (l instanceof Date) { |
|
11328 | if (typeof r === 'string') { |
|
11329 | r = +r; |
|
11330 | } |
|
11331 | var d = new Date(); |
|
11332 | d.setTime(l.getTime()); |
|
11333 | d.setDate(l.getDate() - r); |
|
11334 | return d; |
|
11335 | } else if (typeof r === 'string') { |
|
11336 | var percentage = (+r / 100); |
|
11337 | return l < 0 ? l * (1 + percentage) : l * (1 - percentage); |
|
11338 | } else { |
|
11339 | return l - r; |
|
11340 | } |
|
11341 | }; |
|
11342 | ||
11343 | dc.utils.isNumber = function (n) { |
|
11344 | return n === +n; |
|
@@ 11301-11320 (lines=20) @@ | ||
11298 | ||
11299 | // FIXME: these assume than any string r is a percentage (whether or not it |
|
11300 | // includes %). They also generate strange results if l is a string. |
|
11301 | dc.utils.add = function (l, r) { |
|
11302 | if (typeof r === 'string') { |
|
11303 | r = r.replace('%', ''); |
|
11304 | } |
|
11305 | ||
11306 | if (l instanceof Date) { |
|
11307 | if (typeof r === 'string') { |
|
11308 | r = +r; |
|
11309 | } |
|
11310 | var d = new Date(); |
|
11311 | d.setTime(l.getTime()); |
|
11312 | d.setDate(l.getDate() + r); |
|
11313 | return d; |
|
11314 | } else if (typeof r === 'string') { |
|
11315 | var percentage = (+r / 100); |
|
11316 | return l > 0 ? l * (1 + percentage) : l * (1 - percentage); |
|
11317 | } else { |
|
11318 | return l + r; |
|
11319 | } |
|
11320 | }; |
|
11321 | ||
11322 | dc.utils.subtract = function (l, r) { |
|
11323 | if (typeof r === 'string') { |