Compare commits
No commits in common. "42386051801b6e73abd1256767b4e8c736793d01" and "2d7357f5d0a67329c1d8dee003cae1c188b63ca6" have entirely different histories.
4238605180
...
2d7357f5d0
11 changed files with 173 additions and 176 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -38,4 +38,3 @@ build
|
|||
# Ignore manual compilation results
|
||||
/de/jotoho/
|
||||
/META-INF
|
||||
/.idea
|
||||
|
|
55
app/build.gradle.kts
Normal file
55
app/build.gradle.kts
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Kotlin application project to get you started.
|
||||
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
|
||||
* User Manual available at https://docs.gradle.org/7.2/userguide/building_java_projects.html
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
|
||||
id("org.jetbrains.kotlin.jvm") version "1.+"
|
||||
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Align versions of all Kotlin components
|
||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
|
||||
|
||||
// Use the Kotlin JDK 8 standard library.
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation("com.google.guava:guava:30.1.1-jre")
|
||||
|
||||
// Use the Kotlin test library.
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test")
|
||||
|
||||
// Use the Kotlin JUnit integration.
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "16"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass.set("de.jotoho.waituntil.StartKt")
|
||||
}
|
101
app/src/main/kotlin/de/jotoho/waituntil/start.kt
Normal file
101
app/src/main/kotlin/de/jotoho/waituntil/start.kt
Normal file
|
@ -0,0 +1,101 @@
|
|||
package de.jotoho.waituntil
|
||||
|
||||
import java.util.Locale
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import java.util.TimeZone
|
||||
import java.time.Instant
|
||||
import java.time.LocalTime
|
||||
import java.time.LocalDate
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
// 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
|
||||
// Author: Jonas Tobias Hopusch (@jotoho)
|
||||
|
||||
val langGerman: String = Locale.GERMAN.getLanguage();
|
||||
val applicationOutputLanguage: String = if (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage()))
|
||||
Locale.GERMAN.getLanguage()
|
||||
else Locale.ENGLISH.getLanguage();
|
||||
|
||||
fun waitUntilTimeStamp(timestamp: ZonedDateTime) {
|
||||
Thread.sleep(
|
||||
Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0)
|
||||
);
|
||||
|
||||
val formattedTimeStamp: String = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withZone(TimeZone.getDefault().toZoneId())
|
||||
.format(Instant.now());
|
||||
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> System.err.println("Erfolgreich bis $formattedTimeStamp gewartet!");
|
||||
else -> {
|
||||
System.err.println("Successfully waited until $formattedTimeStamp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime {
|
||||
val userTimeInputRelative = LocalTime.parse(userTimeInputRaw);
|
||||
val userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(), userTimeInputRelative, TimeZone.getDefault().toZoneId());
|
||||
|
||||
val userTimeInputFinal = if (Instant.now().isBefore(userTimeInputAbsolute.toInstant())) userTimeInputAbsolute else userTimeInputAbsolute.plusDays(1);
|
||||
|
||||
val formattedTimeStamp = userTimeInputFinal.format(
|
||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
);
|
||||
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> System.err.println("Dieses Program wird bis zum $formattedTimeStamp warten.");
|
||||
else -> {
|
||||
println("WaitUntil will suspend until $formattedTimeStamp");
|
||||
}
|
||||
}
|
||||
|
||||
return userTimeInputFinal;
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val optionDictionary = mapOf(Pair("-h", "--help"));
|
||||
|
||||
val options = HashSet<String>();
|
||||
val words = HashSet<String>();
|
||||
|
||||
for (arg in args) {
|
||||
if (arg.startsWith("--")) {
|
||||
options.add(arg.substring(startIndex=2))
|
||||
}
|
||||
else if (arg.startsWith('-')) {
|
||||
val translation = optionDictionary.get(arg);
|
||||
if (translation != null)
|
||||
options.add(translation.substring(startIndex=2));
|
||||
else
|
||||
System.err.println("Short-hand '$arg' does not exist. Ignoring!");
|
||||
}
|
||||
else
|
||||
words.add(arg);
|
||||
}
|
||||
|
||||
if (options.contains("help")) {
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> println("Hilfe kommt noch. (Nicht implementiert)");
|
||||
else -> {
|
||||
println("Help is yet to come. (Not implemented)");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (words.size == 1) {
|
||||
val target = calculateAndAnnounceTargetTime(words.iterator().next());
|
||||
waitUntilTimeStamp(target);
|
||||
}
|
||||
else {
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)");
|
||||
else -> {
|
||||
System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})");
|
||||
}
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
14
app/src/test/kotlin/waituntil/AppTest.kt
Normal file
14
app/src/test/kotlin/waituntil/AppTest.kt
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* This Kotlin source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package de.jotoho.waituntil
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class AppTest {
|
||||
@Test fun appHasAGreeting() {
|
||||
val classUnderTest = App()
|
||||
assertNotNull(classUnderTest.greeting, "app should have a greeting")
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
|
||||
kotlin("jvm") version "latest.release"
|
||||
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
}
|
||||
|
||||
group = "de.jotoho"
|
||||
version = "0.1.0"
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Align versions of all Kotlin components
|
||||
implementation(platform(kotlin("bom", "latest.release")))
|
||||
|
||||
// Use the Kotlin standard library.
|
||||
implementation(kotlin("stdlib", "latest.release"))
|
||||
|
||||
// Use the Kotlin test library.
|
||||
testImplementation(kotlin("test", "latest.release"))
|
||||
|
||||
// Use the Kotlin JUnit integration.
|
||||
testImplementation(kotlin("test-junit", "latest.release"))
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "16"
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass.set("de.jotoho.waituntil.StartKt")
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
# Word splitting in find results is intentional!
|
||||
kotlinc $(find src/main -type f -iname '*.kt') -jvm-target 16 -include-runtime -d waituntil.jar
|
||||
kotlinc app/src/main/kotlin/de/jotoho/waituntil/start.kt -jvm-target 16 -include-runtime -d waituntil.jar
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
org.gradle.daemon=false
|
||||
kotlin.code.style=official
|
||||
|
|
|
@ -7,4 +7,5 @@
|
|||
* in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = "waituntil"
|
||||
rootProject.name = "de.jotoho.waituntil"
|
||||
include("app")
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package de.jotoho.waituntil
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.*
|
||||
|
||||
fun waitUntilTimeStamp(timestamp: ZonedDateTime) {
|
||||
Thread.sleep(Instant.now().until(timestamp, ChronoUnit.MILLIS).coerceAtLeast(0))
|
||||
|
||||
val formattedTimeStamp: String =
|
||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withZone(TimeZone.getDefault().toZoneId())
|
||||
.format(Instant.now())
|
||||
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> System.err.println("Erfolgreich bis $formattedTimeStamp gewartet!")
|
||||
else -> {
|
||||
System.err.println("Successfully waited until $formattedTimeStamp")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package de.jotoho.waituntil
|
||||
|
||||
import java.util.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
// 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
|
||||
// Author: Jonas Tobias Hopusch (@jotoho)
|
||||
|
||||
val langGerman: String = Locale.GERMAN.language
|
||||
val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language))
|
||||
Locale.GERMAN.language
|
||||
else Locale.ENGLISH.language
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val optionDictionary = mapOf(Pair("-h", "--help"))
|
||||
|
||||
val options = HashSet<String>()
|
||||
val words = HashSet<String>()
|
||||
|
||||
for (arg in args) {
|
||||
if (arg.startsWith("--")) {
|
||||
options.add(arg.substring(startIndex=2))
|
||||
}
|
||||
else if (arg.startsWith('-')) {
|
||||
if (optionDictionary.containsKey(arg))
|
||||
options.add(optionDictionary[arg]!!.substring(startIndex=2))
|
||||
else
|
||||
System.err.println("Short-hand '$arg' does not exist. Ignoring!")
|
||||
}
|
||||
else
|
||||
words.add(arg)
|
||||
}
|
||||
|
||||
if (options.contains("help")) {
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> println("Hilfe kommt noch. (Nicht implementiert)")
|
||||
else -> {
|
||||
println("Help is yet to come. (Not implemented)")
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (words.size == 1) {
|
||||
val target = calculateAndAnnounceTargetTime(words.iterator().next())
|
||||
waitUntilTimeStamp(target)
|
||||
}
|
||||
else {
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)")
|
||||
else -> {
|
||||
System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})")
|
||||
}
|
||||
}
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package de.jotoho.waituntil
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalTime
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import java.util.TimeZone
|
||||
|
||||
fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime {
|
||||
val userTimeInputRelative = LocalTime.parse(userTimeInputRaw)
|
||||
val userTimeInputAbsolute =
|
||||
ZonedDateTime.of(
|
||||
LocalDate.now(),
|
||||
userTimeInputRelative,
|
||||
TimeZone.getDefault().toZoneId()
|
||||
)
|
||||
|
||||
val userTimeInputFinal =
|
||||
if (Instant.now().isBefore(userTimeInputAbsolute.toInstant()))
|
||||
userTimeInputAbsolute
|
||||
else userTimeInputAbsolute.plusDays(1)
|
||||
|
||||
val formattedTimeStamp =
|
||||
userTimeInputFinal.format(
|
||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
)
|
||||
|
||||
when (applicationOutputLanguage) {
|
||||
langGerman ->
|
||||
System.err.println(
|
||||
"Dieses Program wird bis zum $formattedTimeStamp warten."
|
||||
)
|
||||
else -> {
|
||||
println("WaitUntil will suspend until $formattedTimeStamp")
|
||||
}
|
||||
}
|
||||
|
||||
return userTimeInputFinal
|
||||
}
|
Loading…
Reference in a new issue