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

🚀 Add timespan details expression & Improvements #4661

Merged
merged 35 commits into from
Mar 19, 2024

Conversation

AyhamAl-Ali
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali commented Mar 12, 2022

Description

  • Added a new expression to get timespan information such as days/minutes/etc.
  • Supported weeks, months and years in toString of timespan which makes this code broadcast 365 days output as 1 year instead of 365 days
  • Overall code improvements
  • Supported days in DD:HH:MM:SS[.ms] format
  • Improved toString method
    image

NOTE: 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

@AyhamAl-Ali AyhamAl-Ali added enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature. labels Mar 12, 2022
@AyhamAl-Ali
Copy link
Member Author

I don't much like the usage of indices here so if you have a better and clean way let me know

new NonNullPair<>(names[7], times[7]),
new NonNullPair<>(names[6], times[6]),
new NonNullPair<>(names[5], times[5]),
new NonNullPair<>(names[4], times[4]),
new NonNullPair<>(names[3], times[3]),
new NonNullPair<>(names[2], times[2]),
new NonNullPair<>(names[1], times[1])

Same goes for the new getters

@Pikachu920
Copy link
Member

I don't much like the usage of indices here so if you have a better and clean way let me know

new NonNullPair<>(names[7], times[7]),
new NonNullPair<>(names[6], times[6]),
new NonNullPair<>(names[5], times[5]),
new NonNullPair<>(names[4], times[4]),
new NonNullPair<>(names[3], times[3]),
new NonNullPair<>(names[2], times[2]),
new NonNullPair<>(names[1], times[1])

Same goes for the new getters

it's probably best replaced by an enum

1 similar comment
@Pikachu920
Copy link
Member

I don't much like the usage of indices here so if you have a better and clean way let me know

new NonNullPair<>(names[7], times[7]),
new NonNullPair<>(names[6], times[6]),
new NonNullPair<>(names[5], times[5]),
new NonNullPair<>(names[4], times[4]),
new NonNullPair<>(names[3], times[3]),
new NonNullPair<>(names[2], times[2]),
new NonNullPair<>(names[1], times[1])

Same goes for the new getters

it's probably best replaced by an enum

@AyhamAl-Ali AyhamAl-Ali added the breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) label Jun 11, 2022
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
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("[:.]");
Copy link
Member

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

Copy link
Member Author

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

src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
@AyhamAl-Ali AyhamAl-Ali marked this pull request as draft July 16, 2022 01:45
@AyhamAl-Ali AyhamAl-Ali changed the title 🚀 Add timespan details expression 🚀 Add timespan details expression & Improvements May 15, 2023
Copy link
Member

@APickledWalrus APickledWalrus left a 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 :)

src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
}

public long getMilliSeconds() {
Copy link
Member

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

Copy link
Member Author

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 :)

src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/Timespan.java Outdated Show resolved Hide resolved
@Moderocky Moderocky changed the base branch from master to dev/feature September 18, 2023 09:15
Copy link
Member

@APickledWalrus APickledWalrus left a 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)

@AyhamAl-Ali
Copy link
Member Author

@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.

@AyhamAl-Ali AyhamAl-Ali added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jan 21, 2024
@sovdeeth sovdeeth added the 2.9 Targeting a 2.9.X version release label Jan 29, 2024
@sovdeeth sovdeeth merged commit c59ff5b into SkriptLang:dev/feature Mar 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants