Extensive javadoc cleanup.
Started to convert to the java.time
This commit is contained in:
parent
ad36c18124
commit
89f64cd9f5
27 changed files with 252 additions and 379 deletions
|
@ -87,6 +87,8 @@ compileJava {
|
|||
|
||||
javadoc {
|
||||
options.tags = ['created']
|
||||
options.author = true
|
||||
options.links('http://www.jibble.org/javadocs/pircbot/', 'http://docs.oracle.com/javase/8/docs/api/')
|
||||
}
|
||||
|
||||
jar {
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||
*/
|
||||
public final class ReleaseInfo {
|
||||
private final static String buildmeta = "008";
|
||||
private final static Date date = new Date(1468718052505L);
|
||||
private final static Date date = new Date(1468747036593L);
|
||||
private final static int major = 0;
|
||||
private final static int minor = 7;
|
||||
private final static int patch = 0;
|
||||
|
|
|
@ -34,11 +34,11 @@ package net.thauvin.erik.mobibot;
|
|||
/**
|
||||
* The <code>commands</code>, <code>keywords</code> and <code>arguments</code>.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-26
|
||||
* @since 1.0
|
||||
*/
|
||||
final class Commands {
|
||||
final public class Commands {
|
||||
/**
|
||||
* The add (back)log command.
|
||||
*/
|
||||
|
|
|
@ -38,7 +38,7 @@ import javax.swing.*;
|
|||
/**
|
||||
* The class to handle posts to del.icio.us.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Mar 5, 2005
|
||||
* @since 1.0
|
||||
*/
|
||||
|
|
|
@ -44,7 +44,7 @@ import java.util.List;
|
|||
/**
|
||||
* Manages the feed entries.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-28
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -64,9 +64,7 @@ final class EntriesMgr {
|
|||
*/
|
||||
public static final String XML_EXT = ".xml";
|
||||
|
||||
/**
|
||||
* The maximum number of backlogs to keep.
|
||||
*/
|
||||
// The maximum number of backlogs to keep.
|
||||
private static final int MAX_BACKLOGS = 10;
|
||||
|
||||
/**
|
||||
|
@ -129,7 +127,7 @@ final class EntriesMgr {
|
|||
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(file)))) {
|
||||
final SyndFeed feed = input.build(reader);
|
||||
|
||||
today = Utils.ISO_SDF.format(feed.getPublishedDate());
|
||||
today = Utils.isoLocalDate(feed.getPublishedDate());
|
||||
|
||||
final List items = feed.getEntries();
|
||||
SyndEntry item;
|
||||
|
|
|
@ -38,19 +38,15 @@ import java.util.Date;
|
|||
/**
|
||||
* The class used to store comments associated to a specific entry.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Jan 31, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EntryComment implements Serializable {
|
||||
/**
|
||||
* The serial version UID.
|
||||
*/
|
||||
// The serial version UID.
|
||||
static final long serialVersionUID = 6957415292233553224L;
|
||||
|
||||
/**
|
||||
* The creation date.
|
||||
*/
|
||||
// The creation date.
|
||||
private final Date date = Calendar.getInstance().getTime();
|
||||
|
||||
private String comment = "";
|
||||
|
|
|
@ -43,14 +43,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
/**
|
||||
* The class used to store link entries.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Jan 31, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EntryLink implements Serializable {
|
||||
/**
|
||||
* The serial version UID.
|
||||
*/
|
||||
// The serial version UID.
|
||||
static final long serialVersionUID = 3676245542270899086L;
|
||||
|
||||
// The link's comments
|
||||
|
@ -282,10 +280,44 @@ public class EntryLink implements Serializable {
|
|||
/**
|
||||
* Sets the tags.
|
||||
*
|
||||
* @param tags The tags.
|
||||
* @param tags The space-delimited tags.
|
||||
*/
|
||||
private void setTags(final List<SyndCategory> tags) {
|
||||
this.tags.addAll(tags);
|
||||
public final void setTags(final String tags) {
|
||||
if (tags != null) {
|
||||
final String[] parts = tags.replaceAll(", ", " ").replaceAll(",", " ").split(" ");
|
||||
|
||||
SyndCategoryImpl tag;
|
||||
String part;
|
||||
char mod;
|
||||
|
||||
for (final String rawPart : parts) {
|
||||
part = rawPart.trim();
|
||||
|
||||
if (part.length() >= 2) {
|
||||
tag = new SyndCategoryImpl();
|
||||
tag.setName(part.substring(1).toLowerCase());
|
||||
|
||||
mod = part.charAt(0);
|
||||
|
||||
if (mod == '-') {
|
||||
// Don't remove the channel tag, if any.
|
||||
if (!tag.getName().equals(channel.substring(1))) {
|
||||
this.tags.remove(tag);
|
||||
}
|
||||
} else if (mod == '+') {
|
||||
if (!this.tags.contains(tag)) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
} else {
|
||||
tag.setName(part.trim().toLowerCase());
|
||||
|
||||
if (!this.tags.contains(tag)) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,44 +372,10 @@ public class EntryLink implements Serializable {
|
|||
/**
|
||||
* Sets the tags.
|
||||
*
|
||||
* @param tags The space-delimited tags.
|
||||
* @param tags The tags.
|
||||
*/
|
||||
public final void setTags(final String tags) {
|
||||
if (tags != null) {
|
||||
final String[] parts = tags.replaceAll(", ", " ").replaceAll(",", " ").split(" ");
|
||||
|
||||
SyndCategoryImpl tag;
|
||||
String part;
|
||||
char mod;
|
||||
|
||||
for (final String rawPart : parts) {
|
||||
part = rawPart.trim();
|
||||
|
||||
if (part.length() >= 2) {
|
||||
tag = new SyndCategoryImpl();
|
||||
tag.setName(part.substring(1).toLowerCase());
|
||||
|
||||
mod = part.charAt(0);
|
||||
|
||||
if (mod == '-') {
|
||||
// Don't remove the channel tag, if any.
|
||||
if (!tag.getName().equals(channel.substring(1))) {
|
||||
this.tags.remove(tag);
|
||||
}
|
||||
} else if (mod == '+') {
|
||||
if (!this.tags.contains(tag)) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
} else {
|
||||
tag.setName(part.trim().toLowerCase());
|
||||
|
||||
if (!this.tags.contains(tag)) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void setTags(final List<SyndCategory> tags) {
|
||||
this.tags.addAll(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,34 +44,24 @@ import java.util.List;
|
|||
/**
|
||||
* Reads a RSS feed.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Feb 1, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
class FeedReader implements Runnable {
|
||||
/**
|
||||
* The maximum number of feed items to display.
|
||||
*/
|
||||
// The maximum number of feed items to display.
|
||||
private static final int MAX_ITEMS = 5;
|
||||
|
||||
/**
|
||||
* The tab indent (4 spaces).
|
||||
*/
|
||||
// The tab indent (4 spaces).
|
||||
private static final String TAB_INDENT = " ";
|
||||
|
||||
/**
|
||||
* The bot.
|
||||
*/
|
||||
// The bot.
|
||||
private final Mobibot bot;
|
||||
|
||||
/**
|
||||
* The nick of the person who sent the message.
|
||||
*/
|
||||
// The nick of the person who sent the message.
|
||||
private final String sender;
|
||||
|
||||
/**
|
||||
* The URL to fetch.
|
||||
*/
|
||||
// The URL to fetch.
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,12 +43,14 @@ import org.jsoup.Jsoup;
|
|||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Implements the #mobitopia bot.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Jan 31, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -59,72 +61,48 @@ public class Mobibot extends PircBot {
|
|||
*/
|
||||
public static final int CONNECT_TIMEOUT = 5000;
|
||||
|
||||
/**
|
||||
* The empty title string.
|
||||
*/
|
||||
// The empty title string.
|
||||
static final String NO_TITLE = "No Title";
|
||||
|
||||
/**
|
||||
* The default port.
|
||||
*/
|
||||
// The default port.
|
||||
private static final int DEFAULT_PORT = 6667;
|
||||
|
||||
/**
|
||||
* The info strings.
|
||||
*/
|
||||
// The info strings.
|
||||
private static final String[] INFO_STRS = {
|
||||
ReleaseInfo.getProject() + " v" + ReleaseInfo.getVersion() + " by Erik C. Thauvin (erik@thauvin.net)",
|
||||
"http://www.mobitopia.org/mobibot/"
|
||||
};
|
||||
|
||||
/**
|
||||
* The link match string.
|
||||
*/
|
||||
// The link match string.
|
||||
private static final String LINK_MATCH = "^[hH][tT][tT][pP](|[sS])://.*";
|
||||
|
||||
/**
|
||||
* The default maximum number of entries to display.
|
||||
*/
|
||||
// The default maximum number of entries to display.
|
||||
private static final int MAX_ENTRIES = 8;
|
||||
|
||||
/**
|
||||
* The default maximum recap entries.
|
||||
*/
|
||||
// The default maximum recap entries.
|
||||
private static final int MAX_RECAP = 10;
|
||||
|
||||
/**
|
||||
* The maximum number of times the bot will try to reconnect, if disconnected.
|
||||
*/
|
||||
// The maximum number of times the bot will try to reconnect, if disconnected.
|
||||
private static final int MAX_RECONNECT = 10;
|
||||
|
||||
/**
|
||||
* The number of milliseconds to delay between consecutive messages.
|
||||
*/
|
||||
// The number of milliseconds to delay between consecutive messages.
|
||||
private static final long MESSAGE_DELAY = 1000L;
|
||||
|
||||
/**
|
||||
* The modules.
|
||||
*/
|
||||
// The modules.
|
||||
private static final List<AbstractModule> MODULES = new ArrayList<>(0);
|
||||
|
||||
/**
|
||||
* The start time.
|
||||
*/
|
||||
// The start time.
|
||||
private static final long START_TIME = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
* The tags/categories marker.
|
||||
*/
|
||||
// The tags/categories marker.
|
||||
private static final String TAGS_MARKER = "tags:";
|
||||
|
||||
/**
|
||||
* The version strings.
|
||||
*/
|
||||
// The version strings.
|
||||
private static final String[] VERSION_STRS = {
|
||||
"Version: "
|
||||
+ ReleaseInfo.getVersion()
|
||||
+ " ("
|
||||
+ Utils.ISO_SDF.format(ReleaseInfo.getBuildDate()) + ')',
|
||||
+ Utils.isoLocalDate(ReleaseInfo.getBuildDate()) + ')',
|
||||
"Platform: "
|
||||
+ System.getProperty("os.name")
|
||||
+ " ("
|
||||
|
@ -147,109 +125,67 @@ public class Mobibot extends PircBot {
|
|||
+ ')'
|
||||
};
|
||||
|
||||
/**
|
||||
* The tell object.
|
||||
*/
|
||||
// The tell object.
|
||||
private static Tell tell;
|
||||
|
||||
/**
|
||||
* The main channel.
|
||||
*/
|
||||
// The main channel.
|
||||
private final String channel;
|
||||
|
||||
/**
|
||||
* The commands list.
|
||||
*/
|
||||
// The commands list.
|
||||
private final List<String> commandsList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The entries array.
|
||||
*/
|
||||
// The entries array.
|
||||
private final List<EntryLink> entries = new ArrayList<>(0);
|
||||
|
||||
/**
|
||||
* The history/backlogs array.
|
||||
*/
|
||||
// The history/backlogs array.
|
||||
private final List<String> history = new ArrayList<>(0);
|
||||
|
||||
/**
|
||||
* The ignored nicks array.
|
||||
*/
|
||||
// The ignored nicks array.
|
||||
private final List<String> ignoredNicks = new ArrayList<>(0);
|
||||
|
||||
/**
|
||||
* The IRC port.
|
||||
*/
|
||||
// The IRC port.
|
||||
private final int ircPort;
|
||||
|
||||
/**
|
||||
* The IRC server.
|
||||
*/
|
||||
// The IRC server.
|
||||
private final String ircServer;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*/
|
||||
// The logger.
|
||||
private final Log4JLogger logger = new Log4JLogger(Mobibot.class.getPackage().getName());
|
||||
|
||||
/**
|
||||
* The logger default level.
|
||||
*/
|
||||
// The logger default level.
|
||||
private final Level loggerLevel;
|
||||
|
||||
/**
|
||||
* The log directory.
|
||||
*/
|
||||
// The log directory.
|
||||
private final String logsDir;
|
||||
|
||||
/**
|
||||
* The recap array.
|
||||
*/
|
||||
// The recap array.
|
||||
private final List<String> recap = new ArrayList<>(0);
|
||||
|
||||
/**
|
||||
* The backlogs URL.
|
||||
*/
|
||||
// The backlogs URL.
|
||||
private String backLogsUrl = "";
|
||||
|
||||
/**
|
||||
* The default tags/categories.
|
||||
*/
|
||||
// The default tags/categories.
|
||||
private String defaultTags = "";
|
||||
|
||||
/**
|
||||
* The del.icio.us posts handler.
|
||||
*/
|
||||
// The del.icio.us posts handler.
|
||||
private DeliciousPoster delicious = null;
|
||||
|
||||
/**
|
||||
* The feed URL.
|
||||
*/
|
||||
// The feed URL.
|
||||
private String feedURL = "";
|
||||
|
||||
/**
|
||||
* The ident message.
|
||||
*/
|
||||
// The ident message.
|
||||
private String identMsg = "";
|
||||
|
||||
/**
|
||||
* The ident nick.
|
||||
*/
|
||||
// The ident nick.
|
||||
private String identNick = "";
|
||||
|
||||
/**
|
||||
* The NickServ ident password.
|
||||
*/
|
||||
// The NickServ ident password.
|
||||
private String identPwd = "";
|
||||
|
||||
/**
|
||||
* Today's date.
|
||||
*/
|
||||
// Today's date.
|
||||
private String today = Utils.today();
|
||||
|
||||
/**
|
||||
* The weblog URL.
|
||||
*/
|
||||
// The weblog URL.
|
||||
private String weblogUrl = "";
|
||||
|
||||
/**
|
||||
|
@ -280,9 +216,6 @@ public class Mobibot extends PircBot {
|
|||
// Set the logger level
|
||||
loggerLevel = logger.getLogger().getLevel();
|
||||
|
||||
// Initialization
|
||||
Utils.UTC_SDF.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
// Load the current entries, if any.
|
||||
try {
|
||||
today = EntriesMgr.loadEntries(this.logsDir + EntriesMgr.CURRENT_XML, this.channel, entries);
|
||||
|
@ -1600,7 +1533,7 @@ public class Mobibot extends PircBot {
|
|||
* @param isAction Set to <code>true</code> if the message is an action.
|
||||
*/
|
||||
private void storeRecap(final String sender, final String message, final boolean isAction) {
|
||||
recap.add(Utils.UTC_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ")
|
||||
recap.add(Utils.utcDateTime(LocalDateTime.now(Clock.systemUTC())) + " -> " + sender + (isAction ? " " : ": ")
|
||||
+ message);
|
||||
|
||||
if (recap.size() > MAX_RECAP) {
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
/**
|
||||
* The <code>Tell</code> command.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2016-07-02
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -57,44 +57,28 @@ public class Tell {
|
|||
*/
|
||||
public static final String TELL_DEL_KEYWORD = "del";
|
||||
|
||||
/**
|
||||
* The default maximum number of days to keep messages.
|
||||
*/
|
||||
// The default maximum number of days to keep messages.
|
||||
private static final int DEFAULT_TELL_MAX_DAYS = 7;
|
||||
|
||||
/**
|
||||
* The default message max queue size.
|
||||
*/
|
||||
// The default message max queue size.
|
||||
private static final int DEFAULT_TELL_MAX_SIZE = 50;
|
||||
|
||||
/**
|
||||
* The serialized object file extension.
|
||||
*/
|
||||
// The serialized object file extension.
|
||||
private static final String SER_EXT = ".ser";
|
||||
|
||||
/**
|
||||
* The bot instance.
|
||||
*/
|
||||
// The bot instance.
|
||||
final private Mobibot bot;
|
||||
|
||||
/**
|
||||
* The maximum number of days to keep messages.
|
||||
*/
|
||||
// The maximum number of days to keep messages.
|
||||
final private int maxDays;
|
||||
|
||||
/**
|
||||
* The message maximum queue size.
|
||||
*/
|
||||
// The message maximum queue size.
|
||||
final private int maxSize;
|
||||
|
||||
/**
|
||||
* The messages queue.
|
||||
*/
|
||||
// The messages queue.
|
||||
private final List<TellMessage> messages = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* The serialized object file.
|
||||
*/
|
||||
// The serialized object file.
|
||||
private final String serializedObject;
|
||||
|
||||
public Tell(final Mobibot bot, final String maxDays, final String maxSize) {
|
||||
|
@ -114,7 +98,7 @@ public class Tell {
|
|||
/**
|
||||
* Cleans the messages queue.
|
||||
*
|
||||
* @return <code>True</code> if the queue was cleaned.
|
||||
* @return <code>true</code> if the queue was cleaned.
|
||||
*/
|
||||
private boolean clean() {
|
||||
if (bot.getLogger().isDebugEnabled()) {
|
||||
|
@ -182,14 +166,14 @@ public class Tell {
|
|||
if (message.isReceived()) {
|
||||
bot.send(sender,
|
||||
Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient())
|
||||
+ " [" + Utils.UTC_SDF.format(message.getReceived()) + ", ID: "
|
||||
+ " [" + Utils.utcDateTime(message.getReceived()) + ", ID: "
|
||||
+ message.getId() + ", DELIVERED]",
|
||||
true);
|
||||
|
||||
} else {
|
||||
bot.send(sender,
|
||||
Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient())
|
||||
+ " [" + Utils.UTC_SDF.format(message.getQueued()) + ", ID: "
|
||||
+ " [" + Utils.utcDateTime(message.getQueued()) + ", ID: "
|
||||
+ message.getId() + ", QUEUED]",
|
||||
true);
|
||||
}
|
||||
|
@ -326,7 +310,7 @@ public class Tell {
|
|||
"Your message "
|
||||
+ Utils.reverseColor("[ID " + message.getId() + ']') + " was sent to "
|
||||
+ Utils.bold(message.getRecipient()) + " on "
|
||||
+ Utils.UTC_SDF.format(message.getReceived()),
|
||||
+ Utils.utcDateTime(message.getReceived()),
|
||||
true);
|
||||
|
||||
message.setIsNotified();
|
||||
|
|
|
@ -32,26 +32,27 @@
|
|||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* The <code>TellMessage</code> class.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-24
|
||||
* @since 1.0
|
||||
*/
|
||||
public class TellMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2L;
|
||||
private final String id;
|
||||
private final String message;
|
||||
final private Date queued;
|
||||
final private LocalDateTime queued;
|
||||
private final String recipient;
|
||||
private final String sender;
|
||||
private boolean isNotified;
|
||||
private boolean isReceived;
|
||||
private Date received;
|
||||
private LocalDateTime received;
|
||||
|
||||
/**
|
||||
* Create a new message.
|
||||
|
@ -65,9 +66,8 @@ public class TellMessage implements Serializable {
|
|||
this.recipient = recipient;
|
||||
this.message = message;
|
||||
|
||||
this.queued = Calendar.getInstance().getTime();
|
||||
this.id = Utils.TIMESTAMP_SDF.format(this.queued);
|
||||
|
||||
this.queued = LocalDateTime.now(Clock.systemUTC());
|
||||
this.id = this.queued.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,7 @@ public class TellMessage implements Serializable {
|
|||
*
|
||||
* @return <code>true</code> if the message is queued.
|
||||
*/
|
||||
public Date getQueued() {
|
||||
public LocalDateTime getQueued() {
|
||||
return queued;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class TellMessage implements Serializable {
|
|||
*
|
||||
* @return <code>true</code> if the message has been received.
|
||||
*/
|
||||
public Date getReceived() {
|
||||
public LocalDateTime getReceived() {
|
||||
return received;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ public class TellMessage implements Serializable {
|
|||
* Sets the received flag.
|
||||
*/
|
||||
public void setIsReceived() {
|
||||
received = Calendar.getInstance().getTime();
|
||||
received = LocalDateTime.now(Clock.systemUTC());
|
||||
isReceived = true;
|
||||
}
|
||||
}
|
|
@ -34,15 +34,15 @@ package net.thauvin.erik.mobibot;
|
|||
import org.apache.commons.logging.impl.Log4JLogger;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Tell Messages Manager.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-26
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -65,15 +65,12 @@ final class TellMessagesMgr {
|
|||
* @return <code>True</code> if the queue was cleaned.
|
||||
*/
|
||||
public static boolean clean(final List<TellMessage> tellMessages, final int tellMaxDays) {
|
||||
final Calendar maxDate = Calendar.getInstance();
|
||||
final Date today = new Date();
|
||||
final LocalDateTime today = LocalDateTime.now(Clock.systemUTC());
|
||||
boolean cleaned = false;
|
||||
|
||||
for (final TellMessage message : tellMessages) {
|
||||
maxDate.setTime(message.getQueued());
|
||||
maxDate.add(Calendar.DATE, tellMaxDays);
|
||||
|
||||
if (maxDate.getTime().before(today)) {
|
||||
final LocalDateTime maxDate = message.getQueued().plusDays(tellMaxDays);
|
||||
if (maxDate.isBefore(today)) {
|
||||
tellMessages.remove(message);
|
||||
cleaned = true;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ import java.io.InputStreamReader;
|
|||
* </p>
|
||||
* and follow the prompts/instructions.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="http://twitter4j.org/en/code-examples.html#oauth">http://twitter4j.org/en/code-examples.html#oauth</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @author <a href="http://twitter4j.org/en/code-examples.html#oauth" target="_blank">Twitter4J</a>
|
||||
* @created Sep 13, 2010
|
||||
* @since 1.0
|
||||
*/
|
||||
|
|
|
@ -34,30 +34,19 @@ package net.thauvin.erik.mobibot;
|
|||
import org.jibble.pircbot.Colors;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Miscellaneous utilities class.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-26
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class Utils {
|
||||
/**
|
||||
* The ISO (YYYY-MM-DD) simple date format.
|
||||
*/
|
||||
public static final SimpleDateFormat ISO_SDF = new SimpleDateFormat("yyyy-MM-dd");
|
||||
/**
|
||||
* The timestamp simple date format.
|
||||
*/
|
||||
public static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
/**
|
||||
* The UTC (yyyy-MM-dd HH:mm) simple date format.
|
||||
*/
|
||||
public static final SimpleDateFormat UTC_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
|
||||
/**
|
||||
* Disables the default constructor.
|
||||
*
|
||||
|
@ -225,12 +214,33 @@ final public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*
|
||||
* @param date The date.
|
||||
* @return The date in {@link DateTimeFormatter#ISO_LOCAL_DATE} format.
|
||||
*/
|
||||
public static String isoLocalDate(final Date date) {
|
||||
return isoLocalDate(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*
|
||||
* @param date The date.
|
||||
* @return The date in {@link DateTimeFormatter#ISO_LOCAL_DATE} format.
|
||||
*/
|
||||
public static String isoLocalDate(final LocalDateTime date) {
|
||||
return date.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plural form of a word, if count > 1.
|
||||
*
|
||||
* @param count The count.
|
||||
* @param word The word.
|
||||
* @param plural The plural word.
|
||||
* @return The plural string.
|
||||
*/
|
||||
public static String plural(final long count, final String word, final String plural) {
|
||||
if (count > 1) {
|
||||
|
@ -253,10 +263,10 @@ final public class Utils {
|
|||
/**
|
||||
* Returns today's date.
|
||||
*
|
||||
* @return Today's date in {@link #ISO_SDF ISO} format.
|
||||
* @return Today's date in {@link DateTimeFormatter#ISO_LOCAL_DATE} format.
|
||||
*/
|
||||
public static String today() {
|
||||
return ISO_SDF.format(Calendar.getInstance().getTime());
|
||||
return isoLocalDate(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,4 +285,25 @@ final public class Utils {
|
|||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as <code>yyyy-MM-dd HH:mm</code>
|
||||
*
|
||||
* @param date The date.
|
||||
* @return The fromatted date.
|
||||
*/
|
||||
public static String utcDateTime(final Date date) {
|
||||
return utcDateTime(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as <code>yyyy-MM-dd HH:mm</code>
|
||||
*
|
||||
* @param date The date.
|
||||
* @return The fromatted date.
|
||||
*/
|
||||
public static String utcDateTime(final LocalDateTime date) {
|
||||
return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||
}
|
||||
|
||||
}
|
|
@ -39,7 +39,7 @@ import java.util.*;
|
|||
/**
|
||||
* The <code>Module</code> abstract class.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2016-07-01
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -110,7 +110,7 @@ public abstract class AbstractModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns <codde>true</codde> if the module responds to private messages.
|
||||
* Returns <code>true</code> if the module responds to private messages.
|
||||
*
|
||||
* @return <code>true</code> or <code>false</code>
|
||||
*/
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.text.DecimalFormat;
|
|||
/**
|
||||
* The Calc module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2016-07-01
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -49,7 +49,7 @@ public class Calc extends AbstractModule {
|
|||
/**
|
||||
* The Calc command.
|
||||
*/
|
||||
private static final String CALC_CMD = "calc";
|
||||
public static final String CALC_CMD = "calc";
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
|
|
|
@ -50,7 +50,7 @@ import java.util.TreeMap;
|
|||
/**
|
||||
* The CurrentConverter module.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Feb 11, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -58,26 +58,20 @@ final public class CurrencyConverter extends AbstractModule {
|
|||
/**
|
||||
* The currency command.
|
||||
*/
|
||||
private static final String CURRENCY_CMD = "currency";
|
||||
public static final String CURRENCY_CMD = "currency";
|
||||
|
||||
/**
|
||||
* The rates keyword.
|
||||
*/
|
||||
private static final String CURRENCY_RATES_KEYWORD = "rates";
|
||||
public static final String CURRENCY_RATES_KEYWORD = "rates";
|
||||
|
||||
/**
|
||||
* The exchange rates.
|
||||
*/
|
||||
// The exchange rates.
|
||||
private static final Map<String, String> EXCHANGE_RATES = new TreeMap<>();
|
||||
|
||||
/**
|
||||
* The exchange rates table URL.
|
||||
*/
|
||||
// The exchange rates table URL.
|
||||
private static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
|
||||
|
||||
/**
|
||||
* The last exchange rates table publication date.
|
||||
*/
|
||||
// The last exchange rates table publication date.
|
||||
private static String pubDate = "";
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Random;
|
|||
/**
|
||||
* The Dice module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-28
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -47,7 +47,7 @@ final public class Dice extends AbstractModule {
|
|||
/**
|
||||
* The dice command.
|
||||
*/
|
||||
private final String DICE_CMD = "dice";
|
||||
public static final String DICE_CMD = "dice";
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
|
|
|
@ -45,29 +45,22 @@ import java.net.URLEncoder;
|
|||
/**
|
||||
* The GoogleSearch module.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Feb 7, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class GoogleSearch extends AbstractModule {
|
||||
/**
|
||||
* The Google API Key property.
|
||||
*/
|
||||
private static final String GOOGLE_API_KEY_PROP = "google-api-key";
|
||||
|
||||
/**
|
||||
* The google command.
|
||||
*/
|
||||
private static final String GOOGLE_CMD = "google";
|
||||
public static final String GOOGLE_CMD = "google";
|
||||
|
||||
/**
|
||||
* The Google Custom Search Engine ID property.
|
||||
*/
|
||||
// The Google API Key property.
|
||||
private static final String GOOGLE_API_KEY_PROP = "google-api-key";
|
||||
// The Google Custom Search Engine ID property.
|
||||
private static final String GOOGLE_CSE_KEY_PROP = "google-cse-cx";
|
||||
|
||||
/**
|
||||
* The tab indent (4 spaces).
|
||||
*/
|
||||
// The tab indent (4 spaces).
|
||||
private static final String TAB_INDENT = " ";
|
||||
|
||||
/**
|
||||
|
@ -82,11 +75,7 @@ final public class GoogleSearch extends AbstractModule {
|
|||
@Override
|
||||
public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
if (isEnabled() && args.length() > 0) {
|
||||
if (args.length() > 0) {
|
||||
new Thread(() -> run(bot, sender, args)).start();
|
||||
} else {
|
||||
helpResponse(bot, sender, args, isPrivate);
|
||||
}
|
||||
new Thread(() -> run(bot, sender, args)).start();
|
||||
} else {
|
||||
helpResponse(bot, sender, args, isPrivate);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.net.URLConnection;
|
|||
/**
|
||||
* The Joke module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-20
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -51,11 +51,9 @@ final public class Joke extends AbstractModule {
|
|||
/**
|
||||
* The joke command.
|
||||
*/
|
||||
private static final String JOKE_CMD = "joke";
|
||||
public static final String JOKE_CMD = "joke";
|
||||
|
||||
/**
|
||||
* The ICNDB URL.
|
||||
*/
|
||||
// The ICNDB URL.
|
||||
private static final String JOKE_URL =
|
||||
"http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]";
|
||||
|
||||
|
|
|
@ -41,19 +41,17 @@ import java.net.UnknownHostException;
|
|||
/**
|
||||
* The Lookup module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-26
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class Lookup extends AbstractModule {
|
||||
/**
|
||||
* THe lookup command.
|
||||
* The lookup command.
|
||||
*/
|
||||
private static final String LOOKUP_CMD = "lookup";
|
||||
public static final String LOOKUP_CMD = "lookup";
|
||||
|
||||
/**
|
||||
* The whois host.
|
||||
*/
|
||||
// The whois host.
|
||||
private static final String WHOIS_HOST = "whois.arin.net";
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,14 +40,17 @@ import java.util.Random;
|
|||
/**
|
||||
* The Ping module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2016-07-02
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Ping extends AbstractModule {
|
||||
/**
|
||||
* The ping responses.
|
||||
* The ping command.
|
||||
*/
|
||||
public static final String PING_CMD = "ping";
|
||||
|
||||
// The ping responses.
|
||||
private static final List<String> PINGS =
|
||||
Arrays.asList(
|
||||
"is barely alive.",
|
||||
|
@ -63,11 +66,6 @@ public class Ping extends AbstractModule {
|
|||
"is saving energy: apathetic mode activated.",
|
||||
"is busy. Go away!");
|
||||
|
||||
/**
|
||||
* The ping command.
|
||||
*/
|
||||
private static final String PING_CMD = "ping";
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* The StockQuote module.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Feb 7, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -49,11 +49,9 @@ final public class StockQuote extends AbstractModule {
|
|||
/**
|
||||
* The quote command.
|
||||
*/
|
||||
private static final String STOCK_CMD = "stock";
|
||||
public static final String STOCK_CMD = "stock";
|
||||
|
||||
/**
|
||||
* The Yahoo! stock quote URL.
|
||||
*/
|
||||
// The Yahoo! stock quote URL.
|
||||
private static final String YAHOO_URL = "http://finance.yahoo.com/d/quotes.csv?&f=snl1d1t1c1oghv&e=.csv&s=";
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,21 +39,22 @@ import twitter4j.conf.ConfigurationBuilder;
|
|||
/**
|
||||
* The Twitter module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created Sept 10, 2008
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class Twitter extends AbstractModule {
|
||||
/**
|
||||
* The twitter command.
|
||||
*/
|
||||
public final static String TWITTER_CMD = "twitter";
|
||||
|
||||
// The property keys.
|
||||
private final static String CONSUMER_KEY_PROP = "twitter-consumerKey";
|
||||
private final static String CONSUMER_SECRET_PROP = "twitter-consumerSecret";
|
||||
private final static String TOKEN_PROP = "twitter-token";
|
||||
private final static String TOKEN_SECRET_PROP = "twitter-tokenSecret";
|
||||
|
||||
/**
|
||||
* The twitter command.
|
||||
*/
|
||||
private final static String TWITTER_CMD = "twitter";
|
||||
|
||||
/**
|
||||
* Creates a new {@link Twitter} instance.
|
||||
*/
|
||||
|
|
|
@ -39,25 +39,21 @@ import java.util.Random;
|
|||
/**
|
||||
* The War module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-28
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class War extends AbstractModule {
|
||||
/**
|
||||
* The war command.
|
||||
* The war command
|
||||
*/
|
||||
private static final String WAR_CMD = "war";
|
||||
public static final String WAR_CMD = "war";
|
||||
|
||||
/**
|
||||
* The deck of card.
|
||||
*/
|
||||
// The deck of card.
|
||||
private static final String[] WAR_DECK =
|
||||
new String[]{"Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"};
|
||||
|
||||
/**
|
||||
* The suits for the deck of card.
|
||||
*/
|
||||
// The suits for the deck of card.
|
||||
private static final String[] WAR_SUITS = new String[]{"Hearts", "Spades", "Diamonds", "Clubs"};
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,20 +49,16 @@ import java.util.Date;
|
|||
*/
|
||||
final public class Weather extends AbstractModule {
|
||||
/**
|
||||
* The decimal number format.
|
||||
* The weather command.
|
||||
*/
|
||||
public static final String WEATHER_CMD = "weather";
|
||||
|
||||
// The decimal number format.
|
||||
private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("0.##");
|
||||
|
||||
/**
|
||||
* The URL where the stations are listed.
|
||||
*/
|
||||
// The URL where the stations are listed.
|
||||
private static final String STATIONS_URL = "http://www.rap.ucar.edu/weather/surface/stations.txt";
|
||||
|
||||
/**
|
||||
* THe weather command.
|
||||
*/
|
||||
private static final String WEATHER_CMD = "weather";
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weather} instance.
|
||||
*/
|
||||
|
@ -101,7 +97,7 @@ final public class Weather extends AbstractModule {
|
|||
|
||||
bot.send(sender,
|
||||
"At: "
|
||||
+ Utils.UTC_SDF.format(metar.getDate())
|
||||
+ Utils.utcDateTime(metar.getDate())
|
||||
+ " UTC ("
|
||||
+ (((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L)
|
||||
+ " minutes ago)",
|
||||
|
|
|
@ -34,6 +34,9 @@ package net.thauvin.erik.mobibot.modules;
|
|||
import net.thauvin.erik.mobibot.Mobibot;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
@ -42,29 +45,23 @@ import java.util.TreeMap;
|
|||
/**
|
||||
* The WorldTime module.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @author <a href="mailto:erik@thauvin.net" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2014-04-27
|
||||
* @since 1.0
|
||||
*/
|
||||
final public class WorldTime extends AbstractModule {
|
||||
/**
|
||||
* The beats (Internet Time) keyword.
|
||||
*/
|
||||
private static final String BEATS_KEYWORD = ".beats";
|
||||
|
||||
/**
|
||||
* The supported countries.
|
||||
*/
|
||||
private static final Map<String, String> COUNTRIES_MAP = new TreeMap<>();
|
||||
|
||||
/**
|
||||
* The time command.
|
||||
*/
|
||||
private static final String TIME_CMD = "time";
|
||||
public static final String TIME_CMD = "time";
|
||||
|
||||
/**
|
||||
* The date/time format.
|
||||
*/
|
||||
// The beats (Internet Time) keyword.
|
||||
private static final String BEATS_KEYWORD = ".beats";
|
||||
|
||||
// The supported countries.
|
||||
private static final Map<String, String> COUNTRIES_MAP = new TreeMap<>();
|
||||
|
||||
// The date/time format.
|
||||
private static final SimpleDateFormat TIME_SDF =
|
||||
new SimpleDateFormat("'The time is 'HH:mm' on 'EEEE, d MMMM yyyy' in '");
|
||||
|
||||
|
@ -136,7 +133,7 @@ final public class WorldTime extends AbstractModule {
|
|||
COUNTRIES_MAP.put("BEATS", BEATS_KEYWORD);
|
||||
|
||||
for (final String tz : TimeZone.getAvailableIDs()) {
|
||||
if (!tz.contains("/") && tz.length() == 3 & !COUNTRIES_MAP.containsKey(tz)) {
|
||||
if (!tz.contains("/") && tz.length() == 3 && !COUNTRIES_MAP.containsKey(tz)) {
|
||||
COUNTRIES_MAP.put(tz, tz);
|
||||
}
|
||||
}
|
||||
|
@ -161,8 +158,8 @@ final public class WorldTime extends AbstractModule {
|
|||
response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD);
|
||||
} else {
|
||||
TIME_SDF.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
response = TIME_SDF.format(Calendar.getInstance().getTime()) + tz.substring(tz.indexOf('/') + 1)
|
||||
.replace('_', ' ');
|
||||
response = TIME_SDF.format(Calendar.getInstance().getTime())
|
||||
+ tz.substring(tz.indexOf('/') + 1).replace('_', ' ');
|
||||
}
|
||||
} else {
|
||||
isInvalidTz = true;
|
||||
|
@ -195,31 +192,10 @@ final public class WorldTime extends AbstractModule {
|
|||
* @return The Internet Time string.
|
||||
*/
|
||||
private String internetTime() {
|
||||
final Calendar gc = Calendar.getInstance();
|
||||
|
||||
final int offset = (gc.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000));
|
||||
int hh = gc.get(Calendar.HOUR_OF_DAY);
|
||||
final int mm = gc.get(Calendar.MINUTE);
|
||||
final int ss = gc.get(Calendar.SECOND);
|
||||
|
||||
hh -= offset; // GMT
|
||||
hh += 1; // BMT
|
||||
|
||||
long beats = Math.round(Math.floor((double) ((((hh * 3600) + (mm * 60) + ss) * 1000) / 86400)));
|
||||
|
||||
if (beats >= 1000) {
|
||||
beats -= (long) 1000;
|
||||
} else if (beats < 0) {
|
||||
beats += (long) 1000;
|
||||
}
|
||||
|
||||
if (beats < 10) {
|
||||
return ("@00" + beats);
|
||||
} else if (beats < 100) {
|
||||
return ("@0" + beats);
|
||||
}
|
||||
|
||||
return ('@' + String.valueOf(beats));
|
||||
final ZonedDateTime zdt = ZonedDateTime.now(ZoneId.of("UTC+01:00"));
|
||||
final int beats = (int) ((zdt.get(ChronoField.SECOND_OF_MINUTE) + (zdt.get(ChronoField.MINUTE_OF_HOUR) * 60)
|
||||
+ (zdt.get(ChronoField.HOUR_OF_DAY) * 3600)) / 86.4);
|
||||
return String.format("%c%03d", '@', beats);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue