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
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
870e8ff
🚀 Add timespan details expression
AyhamAl-Ali Mar 12, 2022
5f7f92e
Merge branch 'master' into ench/timespan-improve
AyhamAl-Ali Mar 13, 2022
1669cfa
Changes
AyhamAl-Ali Mar 15, 2022
8fe9d0a
Improvements
AyhamAl-Ali Mar 18, 2022
9367856
Changes
AyhamAl-Ali Mar 20, 2022
cf00390
Add DD:HH:MM:SS.ms + improve toString
AyhamAl-Ali Mar 21, 2022
68a2096
Merge branch 'master' into ench/timespan-improve
AyhamAl-Ali Jun 24, 2022
8af2008
Update src/main/java/ch/njol/skript/util/Timespan.java
AyhamAl-Ali Jul 9, 2022
fdd2c9c
Update src/main/java/ch/njol/skript/util/Timespan.java
AyhamAl-Ali Jul 9, 2022
bf52019
Update src/main/java/ch/njol/skript/util/Timespan.java
AyhamAl-Ali Jul 9, 2022
3a4d6c3
Update src/main/java/ch/njol/skript/util/Timespan.java
AyhamAl-Ali Jul 9, 2022
a32ca2a
Testing
AyhamAl-Ali Jul 9, 2022
6372da2
Improvements - Unfinished code
AyhamAl-Ali Jul 16, 2022
0ec45dd
Update enums
AyhamAl-Ali Jan 1, 2023
9f4bbfb
Merge remote-tracking branch 'AyhamAl-Ali/ench/timespan-improve' into…
AyhamAl-Ali Jan 1, 2023
53ea288
Merge branch 'master' into ench/timespan-improve
AyhamAl-Ali Jan 1, 2023
207f2d7
Fix building
AyhamAl-Ali Jan 1, 2023
4745e8e
Merge remote-tracking branch 'AyhamAl-Ali/ench/timespan-improve' into…
AyhamAl-Ali Jan 1, 2023
56a77af
Test build
AyhamAl-Ali Jan 1, 2023
df3d9a9
Test 2
AyhamAl-Ali Jan 1, 2023
78e8b0e
Fix code
AyhamAl-Ali Jan 1, 2023
0ce18e9
Requested Changes & Improvements
AyhamAl-Ali Apr 18, 2023
6c5683d
Requested Changes
AyhamAl-Ali Apr 19, 2023
fcdb1b6
Merge branch 'master' into ench/timespan-improve
AyhamAl-Ali Apr 19, 2023
201b546
Pikachu's quality requested changes 🚀
AyhamAl-Ali Apr 20, 2023
37afcb9
Merge remote-tracking branch 'AyhamAl-Ali/ench/timespan-improve' into…
AyhamAl-Ali Apr 20, 2023
0283bea
Merge branch 'master' into ench/timespan-improve
TheLimeGlass Aug 5, 2023
2160bdb
Merge remote-tracking branch 'origin/dev/feature' into ench/timespan-…
AyhamAl-Ali Oct 5, 2023
63b281f
Apply suggestions
AyhamAl-Ali Oct 5, 2023
a2be2b1
typo
AyhamAl-Ali Oct 5, 2023
6be6300
Update src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
AyhamAl-Ali Dec 15, 2023
2ac1b90
Merge branch 'dev/feature' into ench/timespan-improve
AyhamAl-Ali Dec 30, 2023
2b18a04
Add Timespan(TimePeriod, long) and deprecate fromTicks
AyhamAl-Ali Jan 21, 2024
1b845c7
Add getAs(TimePeriod)
AyhamAl-Ali Jan 21, 2024
001c9e3
Merge branch 'dev/feature' into ench/timespan-improve
sovdeeth Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprTimespanDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.expressions;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Timespan.TimePeriod;
import ch.njol.util.Kleenean;
import org.eclipse.jdt.annotation.Nullable;

import java.util.Locale;

@Name("Timespan Details")
@Description("Retrieve specific information of a <a href=\"/classes.html#timespan\">timespan</a> such as hours/minutes/etc.")
@Examples({
"set {_t} to difference between now and {Payouts::players::%uuid of player%::last-date}",
"send \"It has been %days of {_t}% day(s) since last payout.\""
})
@Since("INSERT VERSION")
public class ExprTimespanDetails extends SimplePropertyExpression<Timespan, Long> {

static {
register(ExprTimespanDetails.class, Long.class, "(:(tick|second|minute|hour|day|week|month|year))[s]", "timespans");
AyhamAl-Ali marked this conversation as resolved.
Show resolved Hide resolved
}

@SuppressWarnings("NotNullFieldNotInitialized")
private TimePeriod type;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
type = TimePeriod.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH));
return super.init(exprs, matchedPattern, isDelayed, parseResult);
}

@Override
@Nullable
public Long convert(Timespan time) {
return time.getMilliSeconds() / type.getTime();
}

@Override
public Class<? extends Long> getReturnType() {
return Long.class;
}

@Override
protected String getPropertyName() {
return type.name().toLowerCase(Locale.ENGLISH);
}

}
Loading