Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with negative quantities #25

Open
smcabrera opened this issue Mar 4, 2015 · 1 comment
Open

Error with negative quantities #25

smcabrera opened this issue Mar 4, 2015 · 1 comment

Comments

@smcabrera
Copy link
Contributor

Unless I'm missing something really obvious there seems to be a problem with negative numbers. For example if I instantiate a couple of Duration objects...

a = Duration.new(10)
=> #<Duration:0x007f21aa066c88 @seconds=10, @negative=false, @total=10, @weeks=0, @days=0, @hours=0, @minutes=0>
b = Duration.new(-5)
=> #<Duration:0x007f21a9e97150 @seconds=5, @negative=true, @total=5, @weeks=0, @days=0, @hours=0, @minutes=0>

They correctly report whether or not they are negative:

a.negative?
=> false
b.negative?
=> true

But then if I try to add a couple durations together the negative duration doesn't seem to behave as negative:

c = a + b
=> #<Duration:0x007f21a902f180 @seconds=15, @negative=false, @total=15, @weeks=0, @days=0, @hours=0, @minutes=0>

I get a positive 15.

@smcabrera
Copy link
Contributor Author

I've submitted a pull request for a first run at a fix for this problem. Please let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants