Skip to content

duration can be in inconsistent state after subtraction #2166

Closed
@zacronos

Description

@zacronos

I haven't explored to see all the circumstances that can cause it, but I notice that a duration's fields do not necessarily get normalized after subtraction. Depending on how you do the same subtraction (conceptually), you get different results.

Here's a fiddle to see the issue in action:
http://jsfiddle.net/9cs8o1v1/3/

A test that would break due to this bug is:

var subtract1 = moment.duration(600, "days").subtract(1, "year");
var subtract2 = moment.duration(600, "days").subtract(365, "days");
assertEqual(subtract1.months(), subtract2.months());

As you can see in the fiddle, subtract1.months() yields -5, while subtract2.months() yields 7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions