Sha256: d692e4b92f52fdefd857af04851919ccbbc27124ce906abc5d3403fec848ec20

Contents?: true

Size: 1.47 KB

Versions: 19

Compression:

Stored size: 1.47 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

19 entries across 19 versions & 1 rubygems

Version Path
card-mod-date-0.15.6 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.15.0 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.14.2 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.14.1 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.14.0 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.13.4 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.13.3 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.13.2 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.13.1 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.13.0 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.7 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.12.0 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.6 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.5 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.4 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.3 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.2 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.1 vendor/moment/src/test/moment/duration_from_moments.js
card-mod-date-0.11.0 vendor/moment/src/test/moment/duration_from_moments.js