forked from moment/moment
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch core tests to QUnit and es6 modules.
- Loading branch information
Showing
38 changed files
with
6,553 additions
and
7,881 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
var moment = require('../../moment'); | ||
import { module, test } from "../qunit"; | ||
import moment from "../../moment"; | ||
import each from "../helpers/each"; | ||
|
||
exports.daysInMonth = { | ||
setUp : function (done) { | ||
moment.createFromInputFallback = function () { | ||
throw new Error('input not handled by moment'); | ||
}; | ||
done(); | ||
}, | ||
module('days in month'); | ||
|
||
'days in month' : function (test) { | ||
test.expect(24); | ||
var months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], i; | ||
for (i = 0; i < 12; i++) { | ||
test.equal(moment([2012, i]).daysInMonth(), | ||
months[i], | ||
moment([2012, i]).format('L') + ' should have ' + months[i] + ' days. (beginning of month ' + i + ')'); | ||
} | ||
for (i = 0; i < 12; i++) { | ||
test.equal(moment([2012, i, months[i]]).daysInMonth(), | ||
months[i], | ||
moment([2012, i, months[i]]).format('L') + ' should have ' + months[i] + ' days. (end of month ' + i + ')'); | ||
} | ||
test.done(); | ||
}, | ||
test('days in month', function (assert) { | ||
each([31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], function (days, i) { | ||
var firstDay = moment([2012, i]); | ||
var lastDay = moment([2012, i, days]); | ||
assert.equal(firstDay.daysInMonth(), days, firstDay.format('L') + ' should have ' + days + ' days.'); | ||
assert.equal( lastDay.daysInMonth(), days, lastDay.format('L') + ' should have ' + days + ' days.'); | ||
}); | ||
}); | ||
|
||
'days in month leap years' : function (test) { | ||
test.expect(4); | ||
test.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days'); | ||
test.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days'); | ||
test.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days'); | ||
test.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days'); | ||
test.done(); | ||
} | ||
}; | ||
test('days in month leap years', function (assert) { | ||
assert.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days'); | ||
assert.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days'); | ||
assert.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days'); | ||
assert.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days'); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,45 @@ | ||
var moment = require('../../moment'); | ||
|
||
exports.durationFromMoments = { | ||
setUp: function (done) { | ||
moment.createFromInputFallback = function () { | ||
throw new Error('input not handled by moment'); | ||
}; | ||
done(); | ||
}, | ||
|
||
'pure year diff' : function (test) { | ||
var m1 = moment('2012-01-01T00:00:00.000Z'), | ||
m2 = moment('2013-01-01T00:00:00.000Z'); | ||
|
||
test.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference'); | ||
test.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference'); | ||
test.done(); | ||
}, | ||
|
||
'month and day diff' : function (test) { | ||
var m1 = moment('2012-01-15T00:00:00.000Z'), | ||
m2 = moment('2012-02-17T00:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
test.equal(d.get('days'), 2); | ||
test.equal(d.get('months'), 1); | ||
test.done(); | ||
}, | ||
|
||
'day diff, separate months' : function (test) { | ||
var m1 = moment('2012-01-15T00:00:00.000Z'), | ||
m2 = moment('2012-02-13T00:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
test.equal(d.as('days'), 29); | ||
test.done(); | ||
}, | ||
|
||
'hour diff' : function (test) { | ||
var m1 = moment('2012-01-15T17:00:00.000Z'), | ||
m2 = moment('2012-01-16T03:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
test.equal(d.as('hours'), 10); | ||
test.done(); | ||
}, | ||
|
||
'minute diff' : function (test) { | ||
var m1 = moment('2012-01-15T17:45:00.000Z'), | ||
m2 = moment('2012-01-16T03:15:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
test.equal(d.as('hours'), 9.5); | ||
test.done(); | ||
} | ||
}; | ||
import { module, test } from "../qunit"; | ||
import moment from "../../moment"; | ||
|
||
module('duration from moments'); | ||
|
||
test('pure year diff', function (assert) { | ||
var m1 = moment('2012-01-01T00:00:00.000Z'), | ||
m2 = moment('2013-01-01T00:00:00.000Z'); | ||
|
||
assert.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference'); | ||
assert.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference'); | ||
}); | ||
|
||
test('month and day diff', function (assert) { | ||
var m1 = moment('2012-01-15T00:00:00.000Z'), | ||
m2 = moment('2012-02-17T00:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
assert.equal(d.get('days'), 2); | ||
assert.equal(d.get('months'), 1); | ||
}); | ||
|
||
test('day diff, separate months', function (assert) { | ||
var m1 = moment('2012-01-15T00:00:00.000Z'), | ||
m2 = moment('2012-02-13T00:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
assert.equal(d.as('days'), 29); | ||
}); | ||
|
||
test('hour diff', function (assert) { | ||
var m1 = moment('2012-01-15T17:00:00.000Z'), | ||
m2 = moment('2012-01-16T03:00:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
assert.equal(d.as('hours'), 10); | ||
}); | ||
|
||
test('minute diff', function (assert) { | ||
var m1 = moment('2012-01-15T17:45:00.000Z'), | ||
m2 = moment('2012-01-16T03:15:00.000Z'), | ||
d = moment.duration({from: m1, to: m2}); | ||
|
||
assert.equal(d.as('hours'), 9.5); | ||
}); |
Oops, something went wrong.