hhvm / hsl-experimental

Experimental features for the Hack Standard Library
MIT License
23 stars 10 forks source link

[ DateTime | RFC ] `HH\Lib\Experimental\Time::zero()` is neither positive or negative, add `->isPositiveOrZero()` #189

Open lexidor opened 3 years ago

lexidor commented 3 years ago

I believe this might be a language thing. I do not know if this is confusing to others. This might be very be a European thing.

The French have a concept of strictly positive and strictly negative, which match the common English definition, which excludes zero. Interesting to note, the docblock of the class itself does not acknowledge zero, since May be positive or negative seems to suggest that zero is not an option.

/**
 * Represents a time interval (a specific number of hours, minutes, seconds, and
 * nanoseconds). May be positive or negative. All instances are immutable.

May I suggest adding ->isPositiveOrZero() and ->isNegativeOrZero(). Not because ->isPositive() || ->isZero() or !->isNegative() is to hard to write, but as a reminder to programmers who navigate autocomplete to think about what to do with zero. This small reminder might make a large difference.

$z = Time::zero();
// Already exist
$z->isPositive(); // false
$z->isNegative(); // false
// New functions
$z->isPositiveOrZero(); // true
$z->isNegativeOrZero(); // true