-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
🚀 Add timespan details expression & Improvements #4661
🚀 Add timespan details expression & Improvements #4661
Conversation
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
I don't much like the usage of indices here so if you have a better and clean way let me know Skript/src/main/java/ch/njol/skript/util/Timespan.java Lines 51 to 57 in 1669cfa
Same goes for the new getters |
it's probably best replaced by an enum |
1 similar comment
it's probably best replaced by an enum |
long t = 0; | ||
boolean minecraftTime = false; | ||
boolean isMinecraftTimeSet = false; | ||
if (s.matches("^\\d+:\\d\\d(:\\d\\d)?(\\.\\d{1,4})?$")) { // MM:SS[.ms] or HH:MM:SS[.ms] | ||
|
||
if (TIMESPAN_PATTERN.matcher(s).matches()) { // MM:SS[.ms] or HH:MM:SS[.ms] or DD:HH:MM:SS[.ms] | ||
final String[] ss = s.split("[:.]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use regex groups for this instead? Would probably simplify the code below quite a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds a little complex and out-of-scope, maybe in another PR
Co-authored-by: TPGamesNL <[email protected]>
Co-authored-by: TPGamesNL <[email protected]>
Co-authored-by: TPGamesNL <[email protected]>
Co-authored-by: TPGamesNL <[email protected]>
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
… ench/timespan-improve
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these are necessarily required, just think they're worth discussing :)
} | ||
|
||
public long getMilliSeconds() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth adding a default TimePeriod.MILLISECOND
option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that, It's just a 1L
which doesn't have much use in math/comparison otherwise let me know :)
bd134d0
to
3f08853
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
I do still think it would be good to support milliseconds as a TimePeriod (also goes with my other comment about an additional constructor). With that, we would be best off to replace getMilliSeconds()
and getTicks()
with a more generic getAs(TimePeriod)
method (name TBD)
src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Outdated
Show resolved
Hide resolved
@APickledWalrus I have added the suggested constructor and getAs(TimePeriod), as well as deprecating the old methods however, I didn't add the Milliseconds support in TimePeriod as that would break the current Timespan parsing and toString output which should have ticks as the least value since that's what Minecraft support. |
Description
broadcast 365 days
output as 1 year instead of 365 daysDD:HH:MM:SS[.ms]
formatNOTE: This is a breaking change (probably) since some users expect the output to be in days and parsing it as that however the output now supports years, months and weeks therefore this should be either merged in a major update or keep the old behavior of toString
Target Minecraft Versions: Any
Requirements: None
Related Issues: None