Sha256: 012cd14952c9722c6bcb68e85788b2fca912f723f26d222f85a815adbd51a96f

Contents?: true

Size: 1.4 KB

Versions: 27

Compression:

Stored size: 1.4 KB

Contents

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);
});

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
card-1.100.0 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.6 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.5 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.4 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.3 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.2 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.1 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.99.0 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.98.3 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.98.2 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.98.1 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.98.0 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.97.0.1 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.97.0 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.8 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.7 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.6 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.5 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.4 mod/date/vendor/moment/src/test/moment/duration_from_moments.js
card-1.96.3 mod/date/vendor/moment/src/test/moment/duration_from_moments.js