Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Add "Time Until" to ExprTimeSince and Add CondPastFuture

Open sovdeeth opened this issue 2 years ago • 0 comments

Description

Continuation of #5767 as previous author did not want to continue working on it.

Also adds CondPastFuture for testing whether a date is in the past or the future. This is simply a more intuitive syntax for if {_x} < now that also supports multiple dates:

%dates% (is|are)[n't| not] in the (past|future)
%dates% ha(s|ve)[n't| not] passed

This has the issue of being unreliable when using ExprNow (who would do that) so there's an explicit check for ExprNow instead of relying on chance for the two created dates to be the same. I added a check for ExpressionLists with ExprNow in them, but I'm not sure that's worth checking.


breaking change of returning 0 seconds for out-of-range dates instead of null:

Previously I disagreed with this change, as seen here:

My view remains that changing the established behavior doesn't really make sense here; there's no real benefit to 0 timespan vs null imo and the change in behavior isn't worth the slight improvement in intuition.

However, I've thought more about it and I think it has benefits outside of intuition. Returning 0 seconds instead of null allows comparisons to be more reliable, since the returned value is still a timespan and will evaluate accordingly instead of being null and being related to negation.

if time since {_date} not is less than 3 seconds:
# Previously:
# if {_date} is in the future, true. This is kind of strange in my opinion. No time has passed since a future date, so the time since should be less than 3 seconds.
# if {_date} is more than 3 seconds ago, true.
# if {_date} is between 0 and 3 seconds ago, false.
# Now:
# if {_date} is in the future, false.
# if {_date} is more than 3 seconds ago, true.
# if {_date} is between 0 and 3 seconds ago, false.

However, it does cause some significant change. Users may rely on the future date to be null, for example using if time since x to test if a date is in the past instead of using if x is less than now.

if time since {_date} is less than 3 seconds:
# Previously:
# if {_date} is in the future, false.
# if {_date} is more than 3 seconds ago, false.
# if {_date} is between 0 and 3 seconds ago, true.
# Now:
# if {_date} is in the future, true.
# if {_date} is more than 3 seconds ago, false.
# if {_date} is between 0 and 3 seconds ago, true.

More opinions are welcome!


Target Minecraft Versions: any Requirements: none Related Issues: #5766

sovdeeth avatar Nov 24 '23 07:11 sovdeeth