Skip to content

Subtracting two MayaDT objects gives incorrect delta. #151

@jgaines

Description

@jgaines
print(maya.when('tomorrow') - maya.when('today'))

Prints out:

86400 days, 0:00:00

To fix this, in the MayaDT.subtract_date method, specify that you're setting the seconds of the timedelta object you create:

    def subtract_date(self, **kwargs):
        """Returns a timedelta object with the duration between the dates"""
        return timedelta(seconds=self.epoch - kwargs['dt'].epoch)

This will make at least one of your tests fail (same fix should be applied to it, pass the calculated seconds in as seconds:

@pytest.mark.usefixtures("frozen_now")
def test_mayaDT_sub():
    now = maya.now()
    then = now.add(days=1)
    assert then - now == timedelta(seconds=24 * 60 * 60)
    assert now - then == timedelta(seconds=-24 * 60 * 60)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions