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

Support Negative durations. #66

Open
Zatte opened this issue Aug 22, 2023 · 0 comments
Open

Support Negative durations. #66

Zatte opened this issue Aug 22, 2023 · 0 comments
Assignees

Comments

@Zatte
Copy link

Zatte commented Aug 22, 2023

When having a LocalDateTime it would beneficial to "remove" a duration instead of only adding it. I can't seem to find an easy way to of turning a positive duration into a negative duration meaning I end up with this pesky workaround.

multiplier := -1
hours, mins, secs, nsec := duration.Units()
negativeDuration := chrono.DurationOf(chrono.Extent(
	time.Hour*time.Duration(hours)*time.Duration(multiplier) +
  	time.Minute*time.Duration(mins)*time.Duration(multiplier) +
	time.Second*time.Duration(secs)*time.Duration(multiplier) +
	time.Nanosecond*time.Duration(nsec)*time.Duration(multiplier)))

Would be neater if this could be done directly on the underlying data representation.
https://github.com/go-chrono/chrono/blob/a79c6fe84b53/duration.go#L12

Adding something like duration.Mul(multiplier int) could probably come in handy.

@joe-mann joe-mann self-assigned this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants