mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
New improvements
This commit is contained in:
parent
a8e35a7da4
commit
922809c595
1
overtime.txt
Normal file
1
overtime.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
0:09
|
@ -1,6 +1,8 @@
|
|||||||
package rvc.timecalc;
|
package rvc.timecalc;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert
|
* @author Robert
|
||||||
@ -8,9 +10,13 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
boolean test = false;
|
boolean test = false;
|
||||||
|
File starttimeTxt = new File("starttime.txt");
|
||||||
|
File overtimeTxt = new File("overtime.txt");
|
||||||
|
String lastStartTime = Utils.readTextFromFile(starttimeTxt);
|
||||||
|
String lastOvertime = Utils.readTextFromFile(overtimeTxt);
|
||||||
String startTime =
|
String startTime =
|
||||||
test ? "7:00" : (String) JOptionPane.showInputDialog(
|
test ? "7:00" : (String) JOptionPane.showInputDialog(
|
||||||
null,
|
null,
|
||||||
@ -19,7 +25,7 @@ public class Main {
|
|||||||
JOptionPane.PLAIN_MESSAGE,
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
"7:00"
|
lastStartTime == null ? "7:00" : lastStartTime
|
||||||
);
|
);
|
||||||
String overTime =
|
String overTime =
|
||||||
test ? "0:00" : (String) JOptionPane.showInputDialog(
|
test ? "0:00" : (String) JOptionPane.showInputDialog(
|
||||||
@ -29,8 +35,15 @@ public class Main {
|
|||||||
JOptionPane.PLAIN_MESSAGE,
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
"0:00"
|
lastOvertime == null ? "0:00" : lastOvertime
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(!starttimeTxt.exists()) {
|
||||||
|
Utils.writeTextToFile(starttimeTxt, startTime);
|
||||||
|
}
|
||||||
|
if(!overtimeTxt.exists()) {
|
||||||
|
Utils.writeTextToFile(overtimeTxt, overTime);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
TimeCalcWindow timeCalc =
|
TimeCalcWindow timeCalc =
|
||||||
new TimeCalcWindow(startTime, overTime);
|
new TimeCalcWindow(startTime, overTime);
|
||||||
|
54
src/main/java/rvc/timecalc/Utils.java
Normal file
54
src/main/java/rvc/timecalc/Utils.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package rvc.timecalc;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert
|
||||||
|
* @since 15.02.2024
|
||||||
|
*/
|
||||||
|
public class Utils {
|
||||||
|
private Utils() {
|
||||||
|
//Not meant to be instantiated.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count of bytes per one kilobyte.
|
||||||
|
*/
|
||||||
|
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes text to a file.
|
||||||
|
* @param file file
|
||||||
|
* @param text text
|
||||||
|
*/
|
||||||
|
public static void writeTextToFile(final File file, final String text) {
|
||||||
|
FileOutputStream outputStream;
|
||||||
|
try {
|
||||||
|
outputStream = new FileOutputStream(file.getAbsolutePath());
|
||||||
|
byte[] strToBytes = text.getBytes();
|
||||||
|
outputStream.write(strToBytes);
|
||||||
|
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads text from file.
|
||||||
|
* @param file file
|
||||||
|
* @return String
|
||||||
|
* @throws IOException thrown, if an error during reading happens
|
||||||
|
*/
|
||||||
|
public static String readTextFromFile(final File file)
|
||||||
|
throws IOException {
|
||||||
|
return new String(Files.readAllBytes(file.toPath()));
|
||||||
|
}
|
||||||
|
}
|
1
starttime.txt
Normal file
1
starttime.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
6:39
|
Loading…
x
Reference in New Issue
Block a user