<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Dave,<div class=""><br class=""></div><div class="">We had some extensive discussion about this ourselves, but we couldn’t come up with a compelling use case for a negative time interval. Can you describe how you wanted to use it?</div><div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 17, 2016, at 2:01 PM, Dave Lyon via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><p class="">In attempting to use the new DateInterval value type to improve some existing code, I ran in to an issue where DateIntervals cannot be "reverse" intervals, which is contrary to how TimeInterval works, and somewhat confusing.</p><p class="">I would propose that the DateInterval value type should be able to be properly initialized with any TimeInterval, as a reference date and time interval are all that is actually required in order to construct a DateInterval properly.</p><p class="">The simplest solution might be to change the `startDate:interval:` initializer to one allows for negative time intervals, such as:</p><p class="">public init(withInterval: TimeInterval, fromDate: Date) { <br class="">&nbsp; &nbsp;&nbsp;self.start = Date(timeInterval: interval, since: fromDate)<br class="">&nbsp; &nbsp; self.duration = abs(interval)<br class="">}</p><p class="">I believe in general it is preferable to avoid preconditions that require a subset of a given input type (in this case, that TimeInterval be positive or 0), and would prefer to see an API where invalid values are properly converted from the given input to the documented output. E.g. the old “Be generous with input, strict with output” idea.<br class=""></p><p class="">I hope this is the right place to bring this up, but if not I’m happy to move the conversation to Radar or elsewhere.</p><p class="">Thanks!</p></div>
_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></div></body></html>