mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-16 11:37:30 +02:00
Moving the date code out of Util class
This commit is contained in:
@@ -227,7 +227,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.SECOND, (int)delay);
|
||||
c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis())));
|
||||
user.sendMessage(_("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis())));
|
||||
initTimer((long)(delay * 1000.0), target, chargeFor, cause);
|
||||
|
||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||
|
@@ -30,20 +30,20 @@ public class Commandmute extends EssentialsCommand
|
||||
if (args.length > 1)
|
||||
{
|
||||
String time = getFinalArg(args, 1);
|
||||
muteTimestamp = Util.parseDateDiff(time, true);
|
||||
muteTimestamp = DateUtil.parseDateDiff(time, true);
|
||||
}
|
||||
player.setTimestamp(TimestampType.MUTE, muteTimestamp);
|
||||
final boolean muted = player.toggleMuted();
|
||||
sender.sendMessage(
|
||||
muted
|
||||
? (muteTimestamp > 0
|
||||
? _("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp))
|
||||
? _("mutedPlayerFor", player.getDisplayName(), DateUtil.formatDateDiff(muteTimestamp))
|
||||
: _("mutedPlayer", player.getDisplayName()))
|
||||
: _("unmutedPlayer", player.getDisplayName()));
|
||||
player.sendMessage(
|
||||
muted
|
||||
? (muteTimestamp > 0
|
||||
? _("playerMutedFor", Util.formatDateDiff(muteTimestamp))
|
||||
? _("playerMutedFor", DateUtil.formatDateDiff(muteTimestamp))
|
||||
: _("playerMuted"))
|
||||
: _("playerUnmuted"));
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class Commandseen extends EssentialsCommand
|
||||
try
|
||||
{
|
||||
IUser u = getPlayer(args, 0);
|
||||
sender.sendMessage(_("seenOnline", u.getDisplayName(), Util.formatDateDiff(u.getTimestamp(TimestampType.LOGIN))));
|
||||
sender.sendMessage(_("seenOnline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGIN))));
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ public class Commandseen extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
sender.sendMessage(_("seenOffline", u.getDisplayName(), Util.formatDateDiff(u.getTimestamp(TimestampType.LOGOUT))));
|
||||
sender.sendMessage(_("seenOffline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGOUT))));
|
||||
if (u.isBanned())
|
||||
{
|
||||
sender.sendMessage(_("whoisBanned", show ? u.getData().getBan().getReason() : _("true")));
|
||||
|
@@ -38,9 +38,9 @@ public class Commandtempban extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
final String time = getFinalArg(args, 1);
|
||||
final long banTimestamp = Util.parseDateDiff(time, true);
|
||||
final long banTimestamp = DateUtil.parseDateDiff(time, true);
|
||||
|
||||
final String banReason = _("tempBanned", Util.formatDateDiff(banTimestamp));
|
||||
final String banReason = _("tempBanned", DateUtil.formatDateDiff(banTimestamp));
|
||||
user.acquireWriteLock();
|
||||
user.getData().setBan(new Ban());
|
||||
user.getData().getBan().setReason(banReason);
|
||||
|
@@ -59,11 +59,11 @@ public class Commandtogglejail extends EssentialsCommand
|
||||
if (args.length > 2)
|
||||
{
|
||||
final String time = getFinalArg(args, 2);
|
||||
timeDiff = Util.parseDateDiff(time, true);
|
||||
timeDiff = DateUtil.parseDateDiff(time, true);
|
||||
player.setTimestamp(TimestampType.JAIL, timeDiff);
|
||||
}
|
||||
sender.sendMessage((timeDiff > 0
|
||||
? _("playerJailedFor", player.getName(), Util.formatDateDiff(timeDiff))
|
||||
? _("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff))
|
||||
: _("playerJailed", player.getName())));
|
||||
return;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ public class Commandtogglejail extends EssentialsCommand
|
||||
if (args.length >= 2 && player.getData().isJailed() && args[1].equalsIgnoreCase(player.getData().getJail()))
|
||||
{
|
||||
final String time = getFinalArg(args, 2);
|
||||
final long timeDiff = Util.parseDateDiff(time, true);
|
||||
final long timeDiff = DateUtil.parseDateDiff(time, true);
|
||||
player.acquireWriteLock();
|
||||
player.setTimestamp(TimestampType.JAIL, timeDiff);
|
||||
sender.sendMessage(_("jailSentenceExtended", Util.formatDateDiff(timeDiff)));
|
||||
sender.sendMessage(_("jailSentenceExtended", DateUtil.formatDateDiff(timeDiff)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import com.earth2me.essentials.api.ISettings;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import com.earth2me.essentials.user.UserData;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import java.util.Locale;
|
||||
import lombok.Cleanup;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -65,7 +66,7 @@ public class Commandwhois extends EssentialsCommand
|
||||
sender.sendMessage(_("whoisMoney", Util.displayCurrency(user.getMoney(), ess)));
|
||||
sender.sendMessage(_("whoisJail", (user.getData().isJailed()
|
||||
? user.getTimestamp(UserData.TimestampType.JAIL) > 0
|
||||
? Util.formatDateDiff(user.getTimestamp(UserData.TimestampType.JAIL))
|
||||
? DateUtil.formatDateDiff(user.getTimestamp(UserData.TimestampType.JAIL))
|
||||
: _("true")
|
||||
: _("false"))));
|
||||
sender.sendMessage(user.getData().isAfk()
|
||||
|
@@ -9,6 +9,7 @@ import com.earth2me.essentials.api.*;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import com.earth2me.essentials.register.payment.Method;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
@@ -88,7 +89,7 @@ public class User extends UserBase implements IUser
|
||||
cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0));
|
||||
if (cooldownTime.after(now) && !bypassPermission.isAuthorized(this))
|
||||
{
|
||||
throw new CooldownException(Util.formatDateDiff(cooldownTime.getTimeInMillis()));
|
||||
throw new CooldownException(DateUtil.formatDateDiff(cooldownTime.getTimeInMillis()));
|
||||
}
|
||||
}
|
||||
if (set)
|
||||
|
186
Essentials/src/com/earth2me/essentials/utils/DateUtil.java
Normal file
186
Essentials/src/com/earth2me/essentials/utils/DateUtil.java
Normal file
@@ -0,0 +1,186 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DateUtil {
|
||||
public static String formatDateDiff(long date)
|
||||
{
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.setTimeInMillis(date);
|
||||
Calendar now = new GregorianCalendar();
|
||||
return formatDateDiff(now, c);
|
||||
}
|
||||
|
||||
public static String formatDateDiff(Calendar fromDate, Calendar toDate)
|
||||
{
|
||||
boolean future = false;
|
||||
if (toDate.equals(fromDate))
|
||||
{
|
||||
return _("now");
|
||||
}
|
||||
if (toDate.after(fromDate))
|
||||
{
|
||||
future = true;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int[] types = new int[]
|
||||
{
|
||||
Calendar.YEAR,
|
||||
Calendar.MONTH,
|
||||
Calendar.DAY_OF_MONTH,
|
||||
Calendar.HOUR_OF_DAY,
|
||||
Calendar.MINUTE,
|
||||
Calendar.SECOND
|
||||
};
|
||||
String[] names = new String[]
|
||||
{
|
||||
_("year"),
|
||||
_("years"),
|
||||
_("month"),
|
||||
_("months"),
|
||||
_("day"),
|
||||
_("days"),
|
||||
_("hour"),
|
||||
_("hours"),
|
||||
_("minute"),
|
||||
_("minutes"),
|
||||
_("second"),
|
||||
_("seconds")
|
||||
};
|
||||
for (int i = 0; i < types.length; i++)
|
||||
{
|
||||
int diff = dateDiff(types[i], fromDate, toDate, future);
|
||||
if (diff > 0)
|
||||
{
|
||||
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
|
||||
}
|
||||
}
|
||||
if (sb.length() == 0)
|
||||
{
|
||||
return "now";
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
|
||||
{
|
||||
int diff = 0;
|
||||
long savedDate = fromDate.getTimeInMillis();
|
||||
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
|
||||
{
|
||||
savedDate = fromDate.getTimeInMillis();
|
||||
fromDate.add(type, future ? 1 : -1);
|
||||
diff++;
|
||||
}
|
||||
diff--;
|
||||
fromDate.setTimeInMillis(savedDate);
|
||||
return diff;
|
||||
}
|
||||
|
||||
public static long parseDateDiff(String time, boolean future) throws Exception
|
||||
{
|
||||
Pattern timePattern = Pattern.compile(
|
||||
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
||||
Matcher m = timePattern.matcher(time);
|
||||
int years = 0;
|
||||
int months = 0;
|
||||
int weeks = 0;
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
boolean found = false;
|
||||
while (m.find())
|
||||
{
|
||||
if (m.group() == null || m.group().isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < m.groupCount(); i++)
|
||||
{
|
||||
if (m.group(i) != null && !m.group(i).isEmpty())
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
if (m.group(1) != null && !m.group(1).isEmpty())
|
||||
{
|
||||
years = Integer.parseInt(m.group(1));
|
||||
}
|
||||
if (m.group(2) != null && !m.group(2).isEmpty())
|
||||
{
|
||||
months = Integer.parseInt(m.group(2));
|
||||
}
|
||||
if (m.group(3) != null && !m.group(3).isEmpty())
|
||||
{
|
||||
weeks = Integer.parseInt(m.group(3));
|
||||
}
|
||||
if (m.group(4) != null && !m.group(4).isEmpty())
|
||||
{
|
||||
days = Integer.parseInt(m.group(4));
|
||||
}
|
||||
if (m.group(5) != null && !m.group(5).isEmpty())
|
||||
{
|
||||
hours = Integer.parseInt(m.group(5));
|
||||
}
|
||||
if (m.group(6) != null && !m.group(6).isEmpty())
|
||||
{
|
||||
minutes = Integer.parseInt(m.group(6));
|
||||
}
|
||||
if (m.group(7) != null && !m.group(7).isEmpty())
|
||||
{
|
||||
seconds = Integer.parseInt(m.group(7));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
throw new Exception(_("illegalDate"));
|
||||
}
|
||||
Calendar c = new GregorianCalendar();
|
||||
if (years > 0)
|
||||
{
|
||||
c.add(Calendar.YEAR, years * (future ? 1 : -1));
|
||||
}
|
||||
if (months > 0)
|
||||
{
|
||||
c.add(Calendar.MONTH, months * (future ? 1 : -1));
|
||||
}
|
||||
if (weeks > 0)
|
||||
{
|
||||
c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1));
|
||||
}
|
||||
if (days > 0)
|
||||
{
|
||||
c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1));
|
||||
}
|
||||
if (hours > 0)
|
||||
{
|
||||
c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1));
|
||||
}
|
||||
if (minutes > 0)
|
||||
{
|
||||
c.add(Calendar.MINUTE, minutes * (future ? 1 : -1));
|
||||
}
|
||||
if (seconds > 0)
|
||||
{
|
||||
c.add(Calendar.SECOND, seconds * (future ? 1 : -1));
|
||||
}
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
}
|
@@ -8,8 +8,10 @@ import com.earth2me.essentials.external.gnu.inet.encoding.Punycode;
|
||||
import com.earth2me.essentials.external.gnu.inet.encoding.PunycodeException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.Cleanup;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -91,182 +93,7 @@ public final class Util
|
||||
return INVALIDCHARS.matcher(string).replaceAll("");
|
||||
}
|
||||
|
||||
public static String formatDateDiff(long date)
|
||||
{
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.setTimeInMillis(date);
|
||||
Calendar now = new GregorianCalendar();
|
||||
return Util.formatDateDiff(now, c);
|
||||
}
|
||||
|
||||
public static String formatDateDiff(Calendar fromDate, Calendar toDate)
|
||||
{
|
||||
boolean future = false;
|
||||
if (toDate.equals(fromDate))
|
||||
{
|
||||
return _("now");
|
||||
}
|
||||
if (toDate.after(fromDate))
|
||||
{
|
||||
future = true;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int[] types = new int[]
|
||||
{
|
||||
Calendar.YEAR,
|
||||
Calendar.MONTH,
|
||||
Calendar.DAY_OF_MONTH,
|
||||
Calendar.HOUR_OF_DAY,
|
||||
Calendar.MINUTE,
|
||||
Calendar.SECOND
|
||||
};
|
||||
String[] names = new String[]
|
||||
{
|
||||
_("year"),
|
||||
_("years"),
|
||||
_("month"),
|
||||
_("months"),
|
||||
_("day"),
|
||||
_("days"),
|
||||
_("hour"),
|
||||
_("hours"),
|
||||
_("minute"),
|
||||
_("minutes"),
|
||||
_("second"),
|
||||
_("seconds")
|
||||
};
|
||||
for (int i = 0; i < types.length; i++)
|
||||
{
|
||||
int diff = dateDiff(types[i], fromDate, toDate, future);
|
||||
if (diff > 0)
|
||||
{
|
||||
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
|
||||
}
|
||||
}
|
||||
if (sb.length() == 0)
|
||||
{
|
||||
return "now";
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
|
||||
{
|
||||
int diff = 0;
|
||||
long savedDate = fromDate.getTimeInMillis();
|
||||
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
|
||||
{
|
||||
savedDate = fromDate.getTimeInMillis();
|
||||
fromDate.add(type, future ? 1 : -1);
|
||||
diff++;
|
||||
}
|
||||
diff--;
|
||||
fromDate.setTimeInMillis(savedDate);
|
||||
return diff;
|
||||
}
|
||||
|
||||
public static long parseDateDiff(String time, boolean future) throws Exception
|
||||
{
|
||||
Pattern timePattern = Pattern.compile(
|
||||
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
||||
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
||||
Matcher m = timePattern.matcher(time);
|
||||
int years = 0;
|
||||
int months = 0;
|
||||
int weeks = 0;
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
boolean found = false;
|
||||
while (m.find())
|
||||
{
|
||||
if (m.group() == null || m.group().isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < m.groupCount(); i++)
|
||||
{
|
||||
if (m.group(i) != null && !m.group(i).isEmpty())
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
if (m.group(1) != null && !m.group(1).isEmpty())
|
||||
{
|
||||
years = Integer.parseInt(m.group(1));
|
||||
}
|
||||
if (m.group(2) != null && !m.group(2).isEmpty())
|
||||
{
|
||||
months = Integer.parseInt(m.group(2));
|
||||
}
|
||||
if (m.group(3) != null && !m.group(3).isEmpty())
|
||||
{
|
||||
weeks = Integer.parseInt(m.group(3));
|
||||
}
|
||||
if (m.group(4) != null && !m.group(4).isEmpty())
|
||||
{
|
||||
days = Integer.parseInt(m.group(4));
|
||||
}
|
||||
if (m.group(5) != null && !m.group(5).isEmpty())
|
||||
{
|
||||
hours = Integer.parseInt(m.group(5));
|
||||
}
|
||||
if (m.group(6) != null && !m.group(6).isEmpty())
|
||||
{
|
||||
minutes = Integer.parseInt(m.group(6));
|
||||
}
|
||||
if (m.group(7) != null && !m.group(7).isEmpty())
|
||||
{
|
||||
seconds = Integer.parseInt(m.group(7));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
throw new Exception(_("illegalDate"));
|
||||
}
|
||||
Calendar c = new GregorianCalendar();
|
||||
if (years > 0)
|
||||
{
|
||||
c.add(Calendar.YEAR, years * (future ? 1 : -1));
|
||||
}
|
||||
if (months > 0)
|
||||
{
|
||||
c.add(Calendar.MONTH, months * (future ? 1 : -1));
|
||||
}
|
||||
if (weeks > 0)
|
||||
{
|
||||
c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1));
|
||||
}
|
||||
if (days > 0)
|
||||
{
|
||||
c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1));
|
||||
}
|
||||
if (hours > 0)
|
||||
{
|
||||
c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1));
|
||||
}
|
||||
if (minutes > 0)
|
||||
{
|
||||
c.add(Calendar.MINUTE, minutes * (future ? 1 : -1));
|
||||
}
|
||||
if (seconds > 0)
|
||||
{
|
||||
c.add(Calendar.SECOND, seconds * (future ? 1 : -1));
|
||||
}
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
|
||||
// The player can stand inside these materials
|
||||
private static final Set<Integer> AIR_MATERIALS = new HashSet<Integer>();
|
||||
private static final HashSet<Byte> AIR_MATERIALS_TARGET = new HashSet<Byte>();
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import com.earth2me.essentials.api.InvalidNameException;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
@@ -39,7 +40,7 @@ public class UtilTest extends TestCase
|
||||
public void testFDDnow()
|
||||
{
|
||||
Calendar c = new GregorianCalendar();
|
||||
String resp = Util.formatDateDiff(c, c);
|
||||
String resp = DateUtil.formatDateDiff(c, c);
|
||||
assertEquals("now", resp);
|
||||
}
|
||||
|
||||
@@ -48,67 +49,67 @@ public class UtilTest extends TestCase
|
||||
Calendar a, b;
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 1);
|
||||
assertEquals(" 1 second", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 second", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 2);
|
||||
assertEquals(" 2 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 3);
|
||||
assertEquals(" 3 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 1, 0);
|
||||
assertEquals(" 1 minute", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 minute", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 2, 0);
|
||||
assertEquals(" 2 minutes", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 minutes", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 3, 0);
|
||||
assertEquals(" 3 minutes", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 minutes", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 11, 0, 0);
|
||||
assertEquals(" 1 hour", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 hour", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 12, 0, 0);
|
||||
assertEquals(" 2 hours", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 hours", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 13, 0, 0);
|
||||
assertEquals(" 3 hours", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 hours", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 2, 10, 0, 0);
|
||||
assertEquals(" 1 day", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 day", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 3, 10, 0, 0);
|
||||
assertEquals(" 2 days", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 days", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 4, 10, 0, 0);
|
||||
assertEquals(" 3 days", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 days", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 2, 1, 10, 0, 0);
|
||||
assertEquals(" 1 month", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 month", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 3, 1, 10, 0, 0);
|
||||
assertEquals(" 2 months", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 months", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 4, 1, 10, 0, 0);
|
||||
assertEquals(" 3 months", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 months", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2011, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 1 year", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 year", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2012, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 2 years", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 years", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2013, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 3 years", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 years", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2011, 4, 5, 23, 38, 12);
|
||||
assertEquals(" 1 year 3 months 4 days 13 hours 38 minutes 12 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 year 3 months 4 days 13 hours 38 minutes 12 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
||||
b = new GregorianCalendar(2015, 3, 7, 10, 0, 0);
|
||||
assertEquals(" 4 years 5 months 20 days 10 hours 14 minutes 15 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 4 years 5 months 20 days 10 hours 14 minutes 15 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2011, 4, 31, 10, 0, 0);
|
||||
b = new GregorianCalendar(2011, 4, 31, 10, 5, 0);
|
||||
assertEquals(" 5 minutes", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 5 minutes", DateUtil.formatDateDiff(a, b));
|
||||
}
|
||||
|
||||
public void testFDDpast()
|
||||
@@ -116,64 +117,64 @@ public class UtilTest extends TestCase
|
||||
Calendar a, b;
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 59);
|
||||
assertEquals(" 1 second", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 second", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 58);
|
||||
assertEquals(" 2 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 57);
|
||||
assertEquals(" 3 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 0);
|
||||
assertEquals(" 1 minute", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 minute", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 58, 0);
|
||||
assertEquals(" 2 minutes", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 minutes", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 57, 0);
|
||||
assertEquals(" 3 minutes", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 minutes", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 0, 0);
|
||||
assertEquals(" 1 hour", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 hour", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 8, 0, 0);
|
||||
assertEquals(" 2 hours", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 hours", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 7, 0, 0);
|
||||
assertEquals(" 3 hours", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 hours", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 4, 10, 0, 0);
|
||||
assertEquals(" 1 day", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 day", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 3, 10, 0, 0);
|
||||
assertEquals(" 2 days", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 days", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 2, 10, 0, 0);
|
||||
assertEquals(" 3 days", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 days", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 4, 1, 10, 0, 0);
|
||||
assertEquals(" 1 month", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 month", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 3, 1, 10, 0, 0);
|
||||
assertEquals(" 2 months", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 months", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 2, 1, 10, 0, 0);
|
||||
assertEquals(" 3 months", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 months", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2009, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 1 year", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 1 year", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2008, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 2 years", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 2 years", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2007, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 3 years", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 3 years", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2009, 4, 5, 23, 38, 12);
|
||||
assertEquals(" 8 months 26 days 10 hours 21 minutes 48 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 8 months 26 days 10 hours 21 minutes 48 seconds", DateUtil.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
||||
b = new GregorianCalendar(2000, 3, 7, 10, 0, 0);
|
||||
assertEquals(" 10 years 6 months 10 days 13 hours 45 minutes 45 seconds", Util.formatDateDiff(a, b));
|
||||
assertEquals(" 10 years 6 months 10 days 13 hours 45 minutes 45 seconds", DateUtil.formatDateDiff(a, b));
|
||||
}
|
||||
|
||||
public void filenameTest() {
|
||||
|
Reference in New Issue
Block a user