Skip to content

Commit 159faf0

Browse files
committed
Improved Date.diff().
1 parent c703ff2 commit 159faf0

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

utils.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,53 +2314,35 @@ Date.prototype.diff = function(date, type) {
23142314
case 'ss':
23152315
case 'second':
23162316
case 'seconds':
2317-
r = Math.ceil(r / 1000);
2318-
if (r === 0)
2319-
return r.toString().parseInt();
2320-
return r;
2317+
return Math.ceil(r / 1000);
23212318
case 'm':
23222319
case 'mm':
23232320
case 'minute':
23242321
case 'minutes':
2325-
r = Math.ceil((r / 1000) / 60);
2326-
if (r === 0)
2327-
return r.toString().parseInt();
2328-
return r;
2322+
return Math.ceil((r / 1000) / 60);
23292323
case 'h':
23302324
case 'hh':
23312325
case 'hour':
23322326
case 'hours':
2333-
r = Math.ceil(((r / 1000) / 60) / 60);
2334-
if (r === 0)
2335-
return r.toString().parseInt();
2336-
return r;
2327+
return Math.ceil(((r / 1000) / 60) / 60);
23372328
case 'd':
23382329
case 'dd':
23392330
case 'day':
23402331
case 'days':
2341-
r = Math.ceil((((r / 1000) / 60) / 60) / 24);
2342-
if (r === 0)
2343-
return r.toString().parseInt();
2344-
return r;
2332+
return Math.ceil((((r / 1000) / 60) / 60) / 24);
23452333
case 'M':
23462334
case 'MM':
23472335
case 'month':
23482336
case 'months':
23492337
// avg: 28 days per month
2350-
r = Math.ceil((((r / 1000) / 60) / 60) / (24 * 28));
2351-
if (r === 0)
2352-
return r.toString().parseInt();
2353-
return r;
2338+
return Math.ceil((((r / 1000) / 60) / 60) / (24 * 28));
23542339

23552340
case 'y':
23562341
case 'yyyy':
23572342
case 'year':
23582343
case 'years':
23592344
// avg: 28 days per month
2360-
r = Math.ceil((((r / 1000) / 60) / 60) / (24 * 28 * 12));
2361-
if (r === 0)
2362-
return r.toString().parseInt();
2363-
return r;
2345+
return Math.ceil((((r / 1000) / 60) / 60) / (24 * 28 * 12));
23642346
}
23652347

23662348
return NaN;

0 commit comments

Comments
 (0)