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

Fix bugs with Timespan#getAs #6909

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 13 additions & 14 deletions src/main/java/ch/njol/skript/util/Timespan.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
*/
package ch.njol.skript.util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Locale;

import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval;

import ch.njol.skript.Skript;
import ch.njol.skript.localization.GeneralWords;
import ch.njol.skript.localization.Language;
Expand All @@ -38,6 +26,17 @@
import ch.njol.util.NonNullPair;
import ch.njol.util.coll.CollectionUtils;
import ch.njol.yggdrasil.YggdrasilSerializable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Timespan implements YggdrasilSerializable, Comparable<Timespan> { // REMIND unit

Expand Down Expand Up @@ -211,7 +210,7 @@ public Timespan(TimePeriod timePeriod, long time) {
/**
* Builds a Timespan from the given long parameter.
*
* @deprecated Use {@link Timespan#Timespan(TimePeriod, long)}
* @deprecated Use {@link #Timespan(TimePeriod, long)}
*
* @param ticks The amount of Minecraft ticks to convert to a timespan.
* @return Timespan based on the provided long.
Expand Down Expand Up @@ -257,7 +256,7 @@ public long getTicks() {
* @return the amount of TimePeriod this timespan represents.
*/
public long getAs(TimePeriod timePeriod) {
return Math.round(millis * timePeriod.getTime());
return millis / timePeriod.getTime();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/skript/tests/regressions/6908-timespan too big.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test "large timespans truncated to ints":
set {_now} to now
set {_a} to unix timestamp of {_now} * 1 seconds
set {_b} to unix timestamp of 10 minutes from {_now} * 1 second
assert {_b} - {_a} is 10 minutes with "large timespan was truncated"