Compare commits

..

No commits in common. "5919c26c106f2ae79388bd7db65e32288dc50619" and "ad869f734649823dc3addf7a3121c232165f4f75" have entirely different histories.

4 changed files with 22 additions and 23 deletions

View file

@ -47,7 +47,7 @@ tasks.test {
useJUnitPlatform() useJUnitPlatform()
} }
tasks.withType<KotlinCompile> { tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "16" kotlinOptions.jvmTarget = "16"
} }

View file

@ -7,8 +7,8 @@ import java.time.format.FormatStyle
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit
import java.util.* import java.util.*
fun waitUntilTimeStamp(timestamp: ZonedDateTime) { public fun waitUntilTimeStamp(timestamp: ZonedDateTime) {
Thread.sleep(Instant.now().until(timestamp, ChronoUnit.MILLIS).coerceAtLeast(0)) Thread.sleep(Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0))
val formattedTimeStamp: String = val formattedTimeStamp: String =
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)

View file

@ -1,57 +1,56 @@
package de.jotoho.waituntil package de.jotoho.waituntil
import java.util.* import java.util.*
import kotlin.system.exitProcess
// This file contains the main function and other utility function necessary for interpreting the terminal arguments. // This file contains the main function and other utility function necessary for interpreting the terminal arguments.
// See README.md and LICENSE.md for license information // See README.md and LICENSE.md for license information
// Author: Jonas Tobias Hopusch (@jotoho) // Author: Jonas Tobias Hopusch (@jotoho)
val langGerman: String = Locale.GERMAN.language val langGerman: String = Locale.GERMAN.getLanguage();
val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) val applicationOutputLanguage: String = if (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage()))
Locale.GERMAN.language Locale.GERMAN.getLanguage()
else Locale.ENGLISH.language else Locale.ENGLISH.getLanguage();
fun main(args: Array<String>) { fun main(args: Array<String>) {
val optionDictionary = mapOf(Pair("-h", "--help")) val optionDictionary = mapOf(Pair("-h", "--help"));
val options = HashSet<String>() val options = HashSet<String>();
val words = HashSet<String>() val words = HashSet<String>();
for (arg in args) { for (arg in args) {
if (arg.startsWith("--")) { if (arg.startsWith("--")) {
options.add(arg.substring(startIndex=2)) options.add(arg.substring(startIndex=2))
} }
else if (arg.startsWith('-')) { else if (arg.startsWith('-')) {
val translation = optionDictionary[arg] val translation = optionDictionary.get(arg);
if (translation != null) if (translation != null)
options.add(translation.substring(startIndex=2)) options.add(translation.substring(startIndex=2));
else else
System.err.println("Short-hand '$arg' does not exist. Ignoring!") System.err.println("Short-hand '$arg' does not exist. Ignoring!");
} }
else else
words.add(arg) words.add(arg);
} }
if (options.contains("help")) { if (options.contains("help")) {
when (applicationOutputLanguage) { when (applicationOutputLanguage) {
langGerman -> println("Hilfe kommt noch. (Nicht implementiert)") langGerman -> println("Hilfe kommt noch. (Nicht implementiert)");
else -> { else -> {
println("Help is yet to come. (Not implemented)") println("Help is yet to come. (Not implemented)");
} }
} }
} }
else if (words.size == 1) { else if (words.size == 1) {
val target = calculateAndAnnounceTargetTime(words.iterator().next()) val target = calculateAndAnnounceTargetTime(words.iterator().next());
waitUntilTimeStamp(target) waitUntilTimeStamp(target);
} }
else { else {
when (applicationOutputLanguage) { when (applicationOutputLanguage) {
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)");
else -> { else -> {
System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})") System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})");
} }
} }
exitProcess(1) System.exit(1);
} }
} }

View file

@ -8,7 +8,7 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
import java.util.TimeZone import java.util.TimeZone
fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { public fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime {
val userTimeInputRelative = LocalTime.parse(userTimeInputRaw) val userTimeInputRelative = LocalTime.parse(userTimeInputRaw)
val userTimeInputAbsolute = val userTimeInputAbsolute =
ZonedDateTime.of( ZonedDateTime.of(