diff --git a/build.gradle b/build.gradle index 1c4552c..f136ac2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.2" - id "com.github.ben-manes.versions" version "0.12.0" + id "com.github.ben-manes.versions" version "0.13.0" } apply plugin: 'java' @@ -140,4 +140,4 @@ task release(dependsOn: ['wrapper', 'clean', 'deploy']) << { group = 'Publishing' description = 'Releases new version.' isRelease = true -} +} \ No newline at end of file diff --git a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java index 28f2e24..05fdfa2 100644 --- a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java +++ b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java @@ -4,7 +4,7 @@ */ package net.thauvin.erik.mobibot; -import java.util.Date; +import java.time.*; /** * Provides semantic version information. @@ -13,8 +13,9 @@ import java.util.Date; * Annotation Processor */ public final class ReleaseInfo { - private final static String buildmeta = "008"; - private final static Date date = new Date(1468747036593L); + private final static String buildmeta = "009"; + private final static LocalDateTime date = + LocalDateTime.ofInstant(Instant.ofEpochMilli(1468789269982L), ZoneId.systemDefault()); private final static int major = 0; private final static int minor = 7; private final static int patch = 0; @@ -36,7 +37,7 @@ public final class ReleaseInfo { * * @return The build date. */ - public static Date getBuildDate() { + public static LocalDateTime getBuildDate() { return date; } diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index e2b0e74..bdaa024 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -1042,7 +1042,7 @@ public class Mobibot extends PircBot { } } else { final EntryLink entry = entries.get(dupIndex); - send(sender, "Duplicate >> " + Utils.buildLink(dupIndex, entry)); + send(sender, Utils.bold("Duplicate") + " >> " + Utils.buildLink(dupIndex, entry)); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java index 746382e..f5dc381 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java @@ -33,13 +33,11 @@ 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.format.DateTimeFormatter; import java.time.temporal.ChronoField; -import java.util.Calendar; import java.util.Map; -import java.util.TimeZone; import java.util.TreeMap; /** @@ -61,10 +59,6 @@ final public class WorldTime extends AbstractModule { // The supported countries. private static final Map 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 '"); - /** * Creates a new {@link WorldTime} instance. */ @@ -72,8 +66,15 @@ final public class WorldTime extends AbstractModule { commands.add(TIME_CMD); // Initialize the countries map + COUNTRIES_MAP.put("AE", "Asia/Dubai"); + COUNTRIES_MAP.put("AF", "Asia/Kabul"); + COUNTRIES_MAP.put("AQ", "Antarctica/South_Pole"); + COUNTRIES_MAP.put("AT", "Europe/Vienna"); COUNTRIES_MAP.put("AU", "Australia/Sydney"); + COUNTRIES_MAP.put("AKST", "America/Anchorage"); + COUNTRIES_MAP.put("AKDT", "America/Anchorage"); COUNTRIES_MAP.put("BE", "Europe/Brussels"); + COUNTRIES_MAP.put("BR", "America/Sao_Paulo"); COUNTRIES_MAP.put("CA", "America/Montreal"); COUNTRIES_MAP.put("CDT", "America/Chicago"); COUNTRIES_MAP.put("CET", "CET"); @@ -92,19 +93,23 @@ final public class WorldTime extends AbstractModule { COUNTRIES_MAP.put("FR", "Europe/Paris"); COUNTRIES_MAP.put("GB", "Europe/London"); COUNTRIES_MAP.put("GMT", "GMT"); + COUNTRIES_MAP.put("GR", "Europe/Athens"); COUNTRIES_MAP.put("HK", "Asia/Hong_Kong"); - COUNTRIES_MAP.put("HST", "HST"); + COUNTRIES_MAP.put("HST", "Pacific/Honolulu"); COUNTRIES_MAP.put("IE", "Europe/Dublin"); COUNTRIES_MAP.put("IL", "Asia/Tel_Aviv"); - COUNTRIES_MAP.put("IN", "Asia/Calcutta"); + COUNTRIES_MAP.put("IN", "Asia/Kolkata"); + COUNTRIES_MAP.put("IQ", "Asia/Baghdad"); COUNTRIES_MAP.put("IR", "Asia/Tehran"); COUNTRIES_MAP.put("IS", "Atlantic/Reykjavik"); COUNTRIES_MAP.put("IT", "Europe/Rome"); COUNTRIES_MAP.put("JM", "Jamaica"); COUNTRIES_MAP.put("JP", "Asia/Tokyo"); COUNTRIES_MAP.put("LY", "Africa/Tripoli"); + COUNTRIES_MAP.put("MA", "Africa/Casablanca"); COUNTRIES_MAP.put("MDT", "America/Denver"); COUNTRIES_MAP.put("MH", "Kwajalein"); + COUNTRIES_MAP.put("MQ", "America/Martinique"); COUNTRIES_MAP.put("MST", "America/Denver"); COUNTRIES_MAP.put("MX", "America/Mexico_City"); COUNTRIES_MAP.put("NL", "Europe/Amsterdam"); @@ -112,31 +117,34 @@ final public class WorldTime extends AbstractModule { COUNTRIES_MAP.put("NP", "Asia/Katmandu"); COUNTRIES_MAP.put("NZ", "Pacific/Auckland"); COUNTRIES_MAP.put("PDT", "America/Los_Angeles"); + COUNTRIES_MAP.put("PH", "Asia/Manila"); COUNTRIES_MAP.put("PK", "Asia/Karachi"); COUNTRIES_MAP.put("PL", "Europe/Warsaw"); COUNTRIES_MAP.put("PST", "America/Los_Angeles"); COUNTRIES_MAP.put("PT", "Europe/Lisbon"); + COUNTRIES_MAP.put("PR", "America/Puerto_Rico"); COUNTRIES_MAP.put("RU", "Europe/Moscow"); COUNTRIES_MAP.put("SE", "Europe/Stockholm"); COUNTRIES_MAP.put("SG", "Asia/Singapore"); - COUNTRIES_MAP.put("SU", "Europe/Moscow"); COUNTRIES_MAP.put("TH", "Asia/Bangkok"); COUNTRIES_MAP.put("TM", "Asia/Ashgabat"); + COUNTRIES_MAP.put("TN", "Africa/Tunis"); COUNTRIES_MAP.put("TR", "Europe/Istanbul"); COUNTRIES_MAP.put("TW", "Asia/Taipei"); COUNTRIES_MAP.put("UK", "Europe/London"); COUNTRIES_MAP.put("US", "America/New_York"); COUNTRIES_MAP.put("UTC", "UTC"); COUNTRIES_MAP.put("VA", "Europe/Vatican"); + COUNTRIES_MAP.put("VE", "America/Caracas"); COUNTRIES_MAP.put("VN", "Asia/Ho_Chi_Minh"); + COUNTRIES_MAP.put("ZA", "Africa/Johannesburg"); + COUNTRIES_MAP.put("ZULU", "Zulu"); COUNTRIES_MAP.put("INTERNET", BEATS_KEYWORD); COUNTRIES_MAP.put("BEATS", BEATS_KEYWORD); - for (final String tz : TimeZone.getAvailableIDs()) { - if (!tz.contains("/") && tz.length() == 3 && !COUNTRIES_MAP.containsKey(tz)) { - COUNTRIES_MAP.put(tz, tz); - } - } + ZoneId.getAvailableZoneIds().stream().filter( + tz -> !tz.contains("/") && tz.length() == 3 && !COUNTRIES_MAP.containsKey(tz)).forEach( + tz -> COUNTRIES_MAP.put(tz, tz)); } /** @@ -157,13 +165,13 @@ final public class WorldTime extends AbstractModule { if (tz.equals(BEATS_KEYWORD)) { response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD); } else { - TIME_SDF.setTimeZone(TimeZone.getTimeZone(tz)); - response = TIME_SDF.format(Calendar.getInstance().getTime()) + response = ZonedDateTime.now().withZoneSameInstant(ZoneId.of(tz)).format( + DateTimeFormatter.ofPattern("'The time is 'HH:mm' on 'EEEE, d MMMM yyyy' in '")) + tz.substring(tz.indexOf('/') + 1).replace('_', ' '); } } else { isInvalidTz = true; - response = "The supported time zones are: " + COUNTRIES_MAP.keySet().toString(); + response = "The supported countries/zones are: " + COUNTRIES_MAP.keySet().toString(); } if (isPrivate) { diff --git a/version.properties b/version.properties index e552373..30dac58 100644 --- a/version.properties +++ b/version.properties @@ -5,4 +5,4 @@ version.major=0 version.minor=7 version.patch=0 version.prerelease=beta -version.buildmeta=008 +version.buildmeta=009 diff --git a/version.vm b/version.vm new file mode 100644 index 0000000..3921024 --- /dev/null +++ b/version.vm @@ -0,0 +1,173 @@ +############################################################################## +## +## Available variables: +## +## $packageName - The package name. (string) +## $className - The class name. (string) +## $project - The project name. (string) +## $epoch - The build epoch/unix time. (long) +## $major - The major version. (int) +## $minor - The minor version. (int) +## $patch - The patch version. (int) +## $prerelease - The pre-release version. (string) +## $buildmeta - The build metadata version. (string) +## +############################################################################## +/* + * This file is automatically generated. + * Do not modify! -- ALL CHANGES WILL BE ERASED! + */ +package ${packageName}; + +import java.time.*; + +/** + * Provides semantic version information. + * + * @author Semantic Version + * Annotation Processor + */ +public final class ${className} { + private final static String buildmeta = "${buildmeta}"; + private final static LocalDateTime date = + LocalDateTime.ofInstant(Instant.ofEpochMilli(${epoch}L), ZoneId.systemDefault()); + private final static int major = ${major}; + private final static int minor = ${minor}; + private final static int patch = ${patch}; + private final static String prerelease = "${prerelease}"; + private final static String project = "${project}"; + + /** + * Disables the default constructor. + * + * @throws UnsupportedOperationException If the constructor is called. + */ + private ${className}() + throws UnsupportedOperationException { + throw new UnsupportedOperationException("Illegal constructor call."); + } + + /** + * Returns the build date. + * + * @return The build date. + */ + public static LocalDateTime getBuildDate() { + return date; + } + + /** + * Returns the project name. + * + * @return The project name, if any. + */ + public static String getProject() { + return project; + } + + /** + * Returns the full version string. + *

+ * Formatted as: + *

+ * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA] + *
+ *

+ * For example: + *

+ * + * @return The version string. + */ + public static String getVersion() { + return Integer.toString(getMajor()) + '.' + + Integer.toString(getMinor()) + '.' + + Integer.toString(getPatch()) + + getPreRelease(true) + getBuildMetadata(true); + } + + /** + * Returns the major version. + * + * @return The major version. + */ + public static int getMajor() { + return major; + } + + /** + * Returns the minor version. + * + * @return The minor version. + */ + public static int getMinor() { + return minor; + } + + /** + * Returns the patch version. + * + * @return The patch version. + */ + public static int getPatch() { + return patch; + } + + /** + * Returns the pre-release version. + * + * @param isHyphen Prepend a hyphen, if true. + * @return The pre-release version, if any. + */ + public static String getPreRelease(final boolean isHyphen) { + if (prerelease.length() > 0) { + if (isHyphen) { + return '-' + prerelease; + } else { + return prerelease; + } + } + + return ""; + } + + /** + * Returns the pre-release version. + * + * @return The pre-release version, if any. + */ + public static String getPreRelease() { + return getPreRelease(false); + } + + /** + * Returns the build metadata. + * + * @param isPlus Prepend a plus sign, if true. + * @return The build metadata, if any. + */ + public static String getBuildMetadata(final boolean isPlus) { + if (buildmeta.length() > 0) { + if (isPlus) { + return '+' + buildmeta; + } else { + return buildmeta; + } + } + + return ""; + } + + /** + * Returns the build metadata. + * + * @return The build metadata, if any. + */ + public static String getBuildMetadata() { + return getBuildMetadata(false); + } +} \ No newline at end of file