Compare commits

...

30 commits

Author SHA1 Message Date
629fd2a516
Merge branch 'codeowner' into master
Apply codeowner rules after having tested them on github.com

Reviewed-by: Jonas Tobias Hopusch <git@jotoho.de>
2022-07-23 17:28:26 +02:00
35536aa3b2
Mark myself as fallback codeowner for entire repository 2022-07-23 17:27:06 +02:00
428950e45c
Set some formatting settings for features not yet used 2022-03-12 15:54:22 +01:00
ca26a0e652
Some tweaks to the formatting settings 2022-03-12 15:40:06 +01:00
240a3784ed
Introduce and apply IntelliJ IDEA code style settings 2022-03-12 15:24:57 +01:00
5154e8ebfc
Avoid unnecessary string concatenation 2022-03-12 14:36:08 +01:00
653e5295de
Rewrite AppOptions to instead use non-static attributes 2022-03-12 14:20:18 +01:00
a7882ab201
Add missing copyright header to AppOptions.java 2022-03-12 13:59:54 +01:00
e66e3b8483
build: remove devNull variable
This is an imperceptible optimization by reducing the scope of the null stream object
2022-03-12 12:24:54 +01:00
8c6d65f147
Reintroduce shadowJar support using external gradle plugin
Since the project now contains a dependency again (commons-cli), I need to be able to generate
jars with those dependencies packaged. (fat jars)
Partially reverts 28a461b8fc
2022-03-12 12:17:33 +01:00
0aa368d457
Make waiting confirmation message output via logger 2022-03-12 03:51:52 +01:00
99c1bb4d6a
Let IntelliJ format all files 2022-03-12 03:45:06 +01:00
eb64994b5a
Switch to using System.Logger instead of raw outputs 2022-03-12 03:43:03 +01:00
60f20b9549
Add link to project repository to version information 2022-03-12 03:28:21 +01:00
3c40095b1d
Merge branch 'outsource-cli-parsing' into master
Closes https://gitea.jotoho.de/jotoho/waituntil/issues/18
2022-03-12 03:25:41 +01:00
1c48b1861f
Rewrite some error messages for wrong argument amounts 2022-03-12 03:23:28 +01:00
b53e7a617d
Refactor main method to use commons-cli to parse arguments 2022-03-12 03:16:00 +01:00
ddf8047ebd
Disable modularization
The modularization file was heavily interfering with the addition and usage of the commons-cli
dependency which does not have a static module name.

Since the benefits it gave this very small application were miniscule, I have decided to
delete / comment out all relevant configuration
2022-03-12 03:13:30 +01:00
1a25963371
Correct incorrect group for commons-cli dependency 2022-03-12 03:12:58 +01:00
fe50b6b85a
Add commons-cli dependency to gradle project configuration 2022-03-12 01:58:05 +01:00
ae11042442
Merge branch 'update-gradle' into master
Basic maintenance work
2022-02-11 05:24:37 +01:00
f03efe7d79
Upgrade gradle version in properties file to gradle 7.4 2022-02-11 05:20:54 +01:00
af4002a431
Merge branch 'contribution-guidelines' into master 2022-01-28 02:12:38 +01:00
c216f6dcc5
Merge branch 'modify-project-settings' into master 2022-01-28 02:12:22 +01:00
28a461b8fc
Remove fat jar module and use java standard library
Removes usage of org.apache.commons classes and instead relies on functionality of Java itself.
It also removes the now-unnecessary plugin dependency for shadowJars.
2022-01-28 02:06:45 +01:00
6b064eb806
Define gradle version in gradle-wrapper.properties 2022-01-28 01:13:46 +01:00
5f3d176045
Stop excluding gradle directory 2022-01-28 01:10:46 +01:00
5d73c12316
Add instructions on supplying contributor information
This should make adding oneself to AUTHORS.md easier.
2022-01-28 01:04:50 +01:00
f42f289b4e
Add basic AUTHORS.md 2022-01-28 00:58:38 +01:00
bb0ef7631b
Add copyright banner to all java sourcefiles
For the purposes of transparency regarding the FOSS license (AGPLv3+) used by this project,
all source files should contain the standard license header.
2022-01-28 00:31:59 +01:00
13 changed files with 355 additions and 93 deletions

1
.github/CODEOWNERS vendored Normal file
View file

@ -0,0 +1 @@
* @jotoho

8
.gitignore vendored
View file

@ -31,12 +31,12 @@ hs_err_pid*
build build
# Ignore gradle wrapper # Ignore gradle wrapper
/gradle gradlew
/gradlew gradlew.bat
/gradlew.bat
# Ignore manual compilation results # Ignore manual compilation results
/de/jotoho/ /de/jotoho/
/META-INF /META-INF
/.idea /.idea/*
!/.idea/codeStyles/
*.zst *.zst

View file

@ -0,0 +1,84 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" />
<option name="RIGHT_MARGIN" value="100" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<option name="ENABLE_SECOND_REFORMAT" value="true" />
<option name="SOFT_MARGINS" value="80" />
<JavaCodeStyleSettings>
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
<option name="ALIGN_MULTILINE_TEXT_BLOCKS" value="true" />
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
<option name="JD_P_AT_EMPTY_LINES" value="false" />
<option name="JD_KEEP_INVALID_TAGS" value="false" />
<option name="JD_KEEP_EMPTY_LINES" value="false" />
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
<option name="JD_PARAM_DESCRIPTION_ON_NEW_LINE" value="true" />
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CONTINUATION_INDENT_IN_PARAMETER_LISTS" value="false" />
<option name="CONTINUATION_INDENT_IN_ARGUMENT_LISTS" value="false" />
<option name="CONTINUATION_INDENT_FOR_CHAINED_CALLS" value="false" />
<option name="CONTINUATION_INDENT_IN_SUPERTYPE_LISTS" value="false" />
<option name="WRAP_EXPRESSION_BODY_FUNCTIONS" value="1" />
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="0" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_ASSIGNMENT" value="true" />
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="RESOURCE_LIST_WRAP" value="5" />
<option name="EXTENDS_LIST_WRAP" value="1" />
<option name="THROWS_LIST_WRAP" value="1" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="THROWS_KEYWORD_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="2" />
<option name="BINARY_OPERATION_WRAP" value="1" />
<option name="TERNARY_OPERATION_WRAP" value="5" />
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<option name="ASSIGNMENT_WRAP" value="1" />
<option name="WRAP_COMMENTS" value="true" />
<option name="ASSERT_STATEMENT_WRAP" value="1" />
<option name="WRAP_LONG_LINES" value="true" />
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
<option name="ENUM_CONSTANTS_WRAP" value="5" />
<option name="KEEP_BUILDER_METHODS_INDENTS" value="true" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="ASSIGNMENT_WRAP" value="5" />
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
<option name="ENUM_CONSTANTS_WRAP" value="5" />
</codeStyleSettings>
</code_scheme>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

16
AUTHORS.md Normal file
View file

@ -0,0 +1,16 @@
# waituntil Contributors / Authors
By adding their names to this document, contributors agree to license all of their
contributions and patches to the waituntil project [under the AGPL version 3 or later.](./LICENSE.md)
Contributors may choose to supply either their complete legal name, online pseudonym or both.
At least one is required.
The email, website and notes fields are optional but contributors are encouraged
to supply at least one reliable method of communication.
## Maintainer(s)
| full name | pseudonym | email | website | notes |
|-|:-:|-:|-:|-|
| Jonas Tobias Hopusch | jotoho | [contact@jotoho.de](mailto:contact@jotoho.de) | [www.jotoho.de](https://www.jotoho.de/) | original creator |

View file

@ -1,16 +1,29 @@
import java.io.ByteArrayOutputStream
import java.io.OutputStream
plugins { plugins {
// Apply the application plugin to add support for building a CLI application in Java. // Apply the application plugin to add support for building a CLI application in Java.
application application
java
// For generating fat jars id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "latest.release" }
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
implementation(group = "commons-cli", name = "commons-cli", version = "1.5.0")
} }
fun versionBanner(): String { fun versionBanner(): String {
val os = org.apache.commons.io.output.ByteArrayOutputStream() val os = ByteArrayOutputStream()
project.exec { project.exec {
commandLine = "git describe --always --dirty".split(" ") commandLine = "git describe --tags --always --dirty --abbrev".split(" ")
standardOutput = os standardOutput = os
errorOutput = OutputStream.nullOutputStream()
} }
return String(os.toByteArray()).trim() return String(os.toByteArray()).trim()
} }
@ -18,11 +31,6 @@ fun versionBanner(): String {
group = "de.jotoho" group = "de.jotoho"
version = versionBanner() version = versionBanner()
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
java { java {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@ -30,11 +38,10 @@ java {
tasks.jar { tasks.jar {
manifest { manifest {
attributes( attributes("Implementation-Title" to project.name,
"Implementation-Title" to project.name,
"Implementation-Version" to project.version, "Implementation-Version" to project.version,
"Main-Class" to "de.jotoho.waituntil.Main", "Main-Class" to "de.jotoho.waituntil.Main"
"Main-Module" to "de.jotoho.waituntil.main" //"Main-Module" to "de.jotoho.waituntil.main"
) )
} }
} }
@ -42,5 +49,5 @@ tasks.jar {
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClass.set("de.jotoho.waituntil.Main") mainClass.set("de.jotoho.waituntil.Main")
mainModule.set("de.jotoho.waituntil.main") //mainModule.set("de.jotoho.waituntil.main")
} }

View file

@ -0,0 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip

View file

@ -0,0 +1,39 @@
package de.jotoho.waituntil;
/*
waituntil - a tool for delaying command execution until the specified time
Copyright (C) 2022 Jonas Tobias Hopusch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
final class AppOptions {
public final Option help = Option.builder()
.argName("h")
.longOpt("help")
.desc("Shows this help message and exits")
.build();
public final Option version = Option.builder()
.argName("v")
.longOpt("version")
.desc("Shows version information and exits")
.build();
public final Options options = new Options().addOption(help)
.addOption(version);
}

View file

@ -1,10 +1,30 @@
package de.jotoho.waituntil; package de.jotoho.waituntil;
/*
waituntil - a tool for delaying command execution until the specified time
Copyright (C) 2022 Jonas Tobias Hopusch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import java.util.Locale; import java.util.Locale;
public record GlobalConf() { public record GlobalConf() {
public static final String langGerman = "de"; public static final String langGerman = "de";
public static final String applicationOutputLanguage = (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) public static final String applicationOutputLanguage = (Locale.getDefault()
.getLanguage()
.equals(Locale.GERMAN.getLanguage()))
? Locale.GERMAN.getLanguage() ? Locale.GERMAN.getLanguage()
: Locale.ENGLISH.getLanguage(); : Locale.ENGLISH.getLanguage();
} }

View file

@ -1,46 +1,48 @@
package de.jotoho.waituntil; package de.jotoho.waituntil;
import java.util.HashSet; /*
import java.util.Map; waituntil - a tool for delaying command execution until the specified time
Copyright (C) 2022 Jonas Tobias Hopusch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage; import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
import static java.lang.System.Logger.Level;
// 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)
public final class Main { public final class Main {
public static void main(final String[] args) { private static final System.Logger logger = System.getLogger("main");
final var optionDictionary = Map.of("-h", "--help", "-v", "--version");
final var options = new HashSet<String>(); private static void printVersionInformation() {
final var words = new HashSet<String>();
for (final String arg : args) {
if (arg.startsWith("--")) {
options.add(arg.substring(2));
} else if (arg.startsWith("-")) {
if (optionDictionary.containsKey(arg))
options.add(optionDictionary.get(arg).substring(2));
else
System.err.println("Short-hand '$arg' does not exist. Ignoring!");
} else {
words.add(arg);
}
}
if (options.contains("help")) {
switch (applicationOutputLanguage) {
case GlobalConf.langGerman -> System.out.println("Hilfe kommt noch. (Nicht implementiert)");
default -> System.out.println("Help is yet to come. (Not implemented)");
}
} else if (options.contains("version")) {
final var thisPackage = Main.class.getPackage(); final var thisPackage = Main.class.getPackage();
final var appVersion = thisPackage.getImplementationVersion() != null final var appVersion = thisPackage.getImplementationVersion() != null
? thisPackage.getImplementationVersion() ? thisPackage.getImplementationVersion()
: "version unknown"; : "version unknown";
System.out.println("waituntil " + appVersion); System.out.println("waituntil " + appVersion);
System.out.println(""" System.out.println("""
Project Repository: https://gitea.jotoho.de/jotoho/waituntil
This program is free software: you can redistribute it and/or modify it under the terms of the This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, either version 3 of the GNU General Public License as published by the Free Software Foundation, either version 3 of the
@ -49,14 +51,64 @@ public final class Main {
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details."""); See the GNU General Public License for more details.""");
} else if (words.size() == 1) {
final var target = TimeCalculator.calculateAndAnnounceTargetTime(words.iterator().next());
Sleep.waitUntilTimeStamp(target);
} else {
switch (applicationOutputLanguage) {
case GlobalConf.langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (" + words.size() + " erhalten)");
default -> System.err.println("FATAL: Expected one non-flag argument. (Got " + words.size() + ")");
} }
private static void printHelpInformation() {
switch (applicationOutputLanguage) {
case GlobalConf.langGerman -> logger.log(Level.ERROR,
"Hilfe kommt noch. (Nicht " +
"implementiert)");
default -> logger.log(Level.ERROR, "Help is yet to come. (Not implemented)");
}
}
private static CommandLine parseArgs(final Options options, final String[] args)
throws ParseException {
return DefaultParser.builder()
.setStripLeadingAndTrailingQuotes(true)
.build()
.parse(options, args);
}
public synchronized static void main(final String[] args) {
// Retrieve defined CLI options
final var appOptions = new AppOptions();
try {
// Parse CLI
final var parsedArguments = parseArgs(appOptions.options, args);
final var userData = parsedArguments.getArgs();
// Differentiate between usage scenarios
if (parsedArguments.hasOption(appOptions.help)) {
printHelpInformation();
} else if (parsedArguments.hasOption(appOptions.version)) {
printVersionInformation();
} else if (userData.length == 0) {
switch (applicationOutputLanguage) {
case GlobalConf.langGerman -> logger.log(Level.ERROR,
"Es wurde keine Uhrzeit " +
"angegeben.");
default -> logger.log(Level.ERROR, "No target time was provided.");
}
System.exit(1);
} else if (userData.length > 1) {
switch (applicationOutputLanguage) {
case GlobalConf.langGerman -> logger.log(Level.ERROR,
"Zu viele Argumente " +
"wurden angegeben.");
default -> logger.log(Level.ERROR, "Too many arguments provided.");
}
System.exit(1);
} else {
final var target = TimeCalculator.calculateAndAnnounceTargetTime(userData[0]);
Sleep.waitUntilTimeStamp(target);
}
} catch (final ParseException e) {
System.getLogger("main")
.log(Level.ERROR,
"Parsing of arguments failed and the program cannot continue.",
e);
System.exit(1); System.exit(1);
} }
} }

View file

@ -1,24 +1,44 @@
package de.jotoho.waituntil; package de.jotoho.waituntil;
/*
waituntil - a tool for delaying command execution until the specified time
Copyright (C) 2022 Jonas Tobias Hopusch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import java.time.Instant; import java.time.Instant;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.TimeZone;
import java.lang.Math; import static java.lang.System.Logger.Level;
public final class Sleep { public final class Sleep {
public static void waitUntilTimeStamp(ZonedDateTime timestamp) { public static void waitUntilTimeStamp(ZonedDateTime timestamp) {
try { try {
Thread.sleep(Math.max(0, Instant.now().until(timestamp, ChronoUnit.MILLIS))); Thread.sleep(Math.max(0,
Instant.now()
.until(timestamp, ChronoUnit.MILLIS)));
} catch (final InterruptedException ignored) { } catch (final InterruptedException ignored) {
} }
final String formattedTimeStamp = final String formattedTimeStamp = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) .withZone(TimeZone.getDefault()
.withZone(TimeZone.getDefault().toZoneId()) .toZoneId())
.format(Instant.now()); .format(Instant.now());
final String msg = switch (GlobalConf.applicationOutputLanguage) { final String msg = switch (GlobalConf.applicationOutputLanguage) {
@ -27,6 +47,7 @@ public final class Sleep {
}; };
final String msgWithData = msg.formatted(formattedTimeStamp); final String msgWithData = msg.formatted(formattedTimeStamp);
System.err.println(msgWithData); System.getLogger("sleep")
.log(Level.INFO, msgWithData);
} }
} }

View file

@ -1,39 +1,57 @@
package de.jotoho.waituntil; package de.jotoho.waituntil;
/*
waituntil - a tool for delaying command execution until the specified time
Copyright (C) 2022 Jonas Tobias Hopusch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.util.*; import java.util.TimeZone;
import static java.lang.System.Logger.Level;
public final class TimeCalculator { public final class TimeCalculator {
public static ZonedDateTime calculateAndAnnounceTargetTime(final String userTimeInputRaw) { public static ZonedDateTime calculateAndAnnounceTargetTime(final String userTimeInputRaw) {
final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw); final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw);
final var userTimeInputAbsolute = final var userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(),
ZonedDateTime.of(
LocalDate.now(),
userTimeInputRelative, userTimeInputRelative,
TimeZone.getDefault().toZoneId() TimeZone.getDefault()
); .toZoneId());
final var userTimeInputFinal = (Instant.now().isBefore(userTimeInputAbsolute.toInstant())) final var userTimeInputFinal = (Instant.now()
.isBefore(userTimeInputAbsolute.toInstant()))
? userTimeInputAbsolute ? userTimeInputAbsolute
: userTimeInputAbsolute.plusDays(1); : userTimeInputAbsolute.plusDays(1);
final var formattedTimeStamp = final var formattedTimeStamp =
userTimeInputFinal.format( userTimeInputFinal.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
);
final String msg = switch (GlobalConf.applicationOutputLanguage) { final String msg = switch (GlobalConf.applicationOutputLanguage) {
case GlobalConf.langGerman -> "Dieses Program wird bis zum %s warten." case GlobalConf.langGerman -> ("Dieses Program wird bis zum %s warten.").formatted(
.formatted(formattedTimeStamp); formattedTimeStamp);
default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp); default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
}; };
System.out.println(msg); System.getLogger("timecalculator")
.log(Level.INFO, msg);
return userTimeInputFinal; return userTimeInputFinal;
} }

View file

@ -1,2 +0,0 @@
module de.jotoho.waituntil.main {
}