mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
patch2
This commit is contained in:
parent
9756a2fd6a
commit
7b55fc7be1
@ -27,7 +27,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
private final TimeCalcApp timeCalcApp;
|
private final TimeCalcApp timeCalcApp;
|
||||||
private final MainWindow mainWindow;
|
private final MainWindow mainWindow;
|
||||||
private final Time time;
|
private final Time time;
|
||||||
private boolean changeByOneHour = false;
|
private boolean changeByFiveMinutes = false;
|
||||||
|
|
||||||
public TimeCalcKeyAdapter(
|
public TimeCalcKeyAdapter(
|
||||||
TimeCalcConfiguration timeCalcConfiguration,
|
TimeCalcConfiguration timeCalcConfiguration,
|
||||||
@ -78,7 +78,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
boolean increase = shiftDown;
|
boolean increase = shiftDown;
|
||||||
boolean decrease = ctrlDown;
|
boolean decrease = ctrlDown;
|
||||||
boolean reset = altDown;
|
boolean reset = altDown;
|
||||||
TTime changeTTime = changeByOneHour ? TTime.T_TIME_ONE_HOUR : TTime.T_TIME_ONE_MINUTE;
|
TTime changeTTime = changeByFiveMinutes ? TTime.T_TIME_FIVE_MINUTES : TTime.T_TIME_ONE_MINUTE;
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.VK_Y: {
|
case KeyEvent.VK_Y: {
|
||||||
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
|
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
|
||||||
@ -161,8 +161,8 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KeyEvent.VK_C: {
|
case KeyEvent.VK_C: {
|
||||||
this.changeByOneHour = increase;
|
this.changeByFiveMinutes = increase;
|
||||||
Utils.showNotification("Time will be changed by 1 " + (increase ? "hour" : "minute") + ".");
|
Utils.showNotification("Time will be changed by " + (increase ? "5 minutes" : "1 minute") + ".");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KeyEvent.VK_E: {
|
case KeyEvent.VK_E: {
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.controls;
|
package org.nanoboot.utils.timecalc.swing.controls;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.windows.MainWindow;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.property.ChangeListener;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import org.nanoboot.utils.timecalc.swing.windows.MainWindow;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -35,7 +39,13 @@ public class TTextField extends JTextField implements GetProperty {
|
|||||||
= new StringProperty("visibilityProperty",
|
= new StringProperty("visibilityProperty",
|
||||||
Visibility.STRONGLY_COLORED.name());
|
Visibility.STRONGLY_COLORED.name());
|
||||||
public final StringProperty valueProperty = new StringProperty();
|
public final StringProperty valueProperty = new StringProperty();
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private ChangeListener vetoableChangeListener = null;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean editingOnlyInDialog = false;
|
||||||
public TTextField() {
|
public TTextField() {
|
||||||
this("", 0);
|
this("", 0);
|
||||||
}
|
}
|
||||||
@ -45,9 +55,23 @@ public class TTextField extends JTextField implements GetProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TTextField(String s, int customWidth) {
|
public TTextField(String s, int customWidth) {
|
||||||
|
this(s, customWidth, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TTextField(String s, int customWidth, boolean editingOnlyInDialog) {
|
||||||
|
this(s, customWidth, editingOnlyInDialog, null);
|
||||||
|
}
|
||||||
|
public TTextField(String s, int customWidth, boolean editingOnlyInDialog, ChangeListener vetoableChangeListener) {
|
||||||
super(s);
|
super(s);
|
||||||
|
setEditingOnlyInDialog(editingOnlyInDialog);
|
||||||
|
setVetoableChangeListener(vetoableChangeListener);
|
||||||
this.customWidth = customWidth;
|
this.customWidth = customWidth;
|
||||||
valueProperty.setValue(s);
|
valueProperty.setValue(s);
|
||||||
|
new Timer(100, e -> {
|
||||||
|
if (editingOnlyInDialog) {
|
||||||
|
setEditable(false);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
getDocument()
|
getDocument()
|
||||||
.addDocumentListener(new DocumentListener() {
|
.addDocumentListener(new DocumentListener() {
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
@ -67,6 +91,40 @@ public class TTextField extends JTextField implements GetProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addMouseListener((MouseClickedListener) f -> {
|
||||||
|
if(editingOnlyInDialog) {
|
||||||
|
String result = (String) JOptionPane.showInputDialog(
|
||||||
|
null,
|
||||||
|
"Select new value",
|
||||||
|
"New value",
|
||||||
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
getText()
|
||||||
|
);
|
||||||
|
if (result != null) {
|
||||||
|
String oldText = getText();
|
||||||
|
boolean vetoed = false;
|
||||||
|
if(vetoableChangeListener != null) {
|
||||||
|
try {
|
||||||
|
vetoableChangeListener
|
||||||
|
.changed(null, oldText, result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
vetoed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!vetoed) {
|
||||||
|
TTime tTime = new TTime(result);
|
||||||
|
result = tTime.toString().substring(0, tTime.isNegative() ? 6 : 5);
|
||||||
|
setText(result);
|
||||||
|
valueProperty.setValue(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
|
||||||
valueProperty.addListener(e
|
valueProperty.addListener(e
|
||||||
-> {
|
-> {
|
||||||
if (!valueProperty.getValue().equals(getText())) {
|
if (!valueProperty.getValue().equals(getText())) {
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.windows;
|
package org.nanoboot.utils.timecalc.swing.windows;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.SmallTButton;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.TTextField;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.TLabel;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.TCheckBox;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.TButton;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.controls.ComponentRegistry;
|
|
||||||
import org.nanoboot.utils.timecalc.app.CommandActionListener;
|
import org.nanoboot.utils.timecalc.app.CommandActionListener;
|
||||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcApp;
|
import org.nanoboot.utils.timecalc.app.TimeCalcApp;
|
||||||
@ -15,6 +8,22 @@ import org.nanoboot.utils.timecalc.app.TimeCalcKeyAdapter;
|
|||||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
|
import org.nanoboot.utils.timecalc.entity.WorkingDay;
|
||||||
|
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
||||||
|
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.ActivityRepositorySQLiteImpl;
|
||||||
|
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.WorkingDayRepositorySQLiteImpl;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.AboutButton;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.WeekStatistics;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.ComponentRegistry;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.SmallTButton;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.TButton;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.TCheckBox;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.TLabel;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.TTextField;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
|
import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.Battery;
|
import org.nanoboot.utils.timecalc.swing.progress.Battery;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
|
import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
|
||||||
@ -33,6 +42,9 @@ import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
|||||||
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.property.ChangeListener;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@ -44,19 +56,11 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import org.nanoboot.utils.timecalc.entity.WorkingDay;
|
import java.util.stream.Collectors;
|
||||||
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
|
||||||
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.ActivityRepositorySQLiteImpl;
|
|
||||||
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.WorkingDayRepositorySQLiteImpl;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.AboutButton;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.WeekStatistics;
|
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
|
||||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -103,10 +107,18 @@ public class MainWindow extends TWindow {
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
this.arrivalTextField = new TTextField(Constants.DEFAULT_ARRIVAL_TIME, 40);
|
ChangeListener valueMustBeTime = new ChangeListener() {
|
||||||
this.overtimeTextField = new TTextField(Constants.DEFAULT_OVERTIME, 40);
|
@Override
|
||||||
this.workingTimeTextField = new TTextField("8:00", 40);
|
public void changed(Property property, Object oldValue,
|
||||||
this.pauseTimeTextField = new TTextField("0:30", 40);
|
Object newValue) {
|
||||||
|
new TTime((String) newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.arrivalTextField = new TTextField(Constants.DEFAULT_ARRIVAL_TIME, 40, true,valueMustBeTime);
|
||||||
|
this.overtimeTextField = new TTextField(Constants.DEFAULT_OVERTIME, 40, true,valueMustBeTime);
|
||||||
|
this.workingTimeTextField = new TTextField("08:00", 40, true,valueMustBeTime);
|
||||||
|
this.pauseTimeTextField = new TTextField("00:30", 40, true,valueMustBeTime);
|
||||||
|
|
||||||
this.noteTextField = new TTextField("", 100);
|
this.noteTextField = new TTextField("", 100);
|
||||||
this.departureTextField = new TTextField();
|
this.departureTextField = new TTextField();
|
||||||
this.elapsedTextField = new TTextField("", 100);
|
this.elapsedTextField = new TTextField("", 100);
|
||||||
@ -338,10 +350,6 @@ public class MainWindow extends TWindow {
|
|||||||
noteTextField.setBoundsFromLeft(noteTextFieldLabel);
|
noteTextField.setBoundsFromLeft(noteTextFieldLabel);
|
||||||
timeOffCheckBox.setBoundsFromLeft(noteTextField);
|
timeOffCheckBox.setBoundsFromLeft(noteTextField);
|
||||||
//
|
//
|
||||||
arrivalTextField.setEditable(false);
|
|
||||||
overtimeTextField.setEditable(false);
|
|
||||||
workingTimeTextField.setEditable(false);
|
|
||||||
pauseTimeTextField.setEditable(false);
|
|
||||||
|
|
||||||
add(arrivalTextFieldLabel);
|
add(arrivalTextFieldLabel);
|
||||||
add(arrivalTextField);
|
add(arrivalTextField);
|
||||||
@ -670,43 +678,84 @@ public class MainWindow extends TWindow {
|
|||||||
forgetOvertimeProperty.setValue(wd.getForgetOvertime());
|
forgetOvertimeProperty.setValue(wd.getForgetOvertime());
|
||||||
} else {
|
} else {
|
||||||
Calendar cal = time.asCalendar();
|
Calendar cal = time.asCalendar();
|
||||||
|
wd = new WorkingDay();
|
||||||
|
{
|
||||||
|
Calendar cal2 = Calendar.getInstance();
|
||||||
|
cal2.setTime(cal.getTime());
|
||||||
|
List<WorkingDay> arrivals = new ArrayList<>();
|
||||||
|
for(int i = 1; i <= 90; i++) {
|
||||||
|
cal2.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
|
WorkingDay wd_ = workingDayRepository.read(cal2);
|
||||||
|
if(wd_ == null || wd_.isThisDayTimeOff()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
arrivals.add(wd_);
|
||||||
|
if(arrivals.size() == 20) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!arrivals.isEmpty()) {
|
||||||
|
// double averageArrival = arrivals.size() == 1 ? arrivals.get(0) : arrivals.stream().mapToDouble(Double::doubleValue).sorted().average().getAsDouble();
|
||||||
|
double medianArrival = arrivals.stream().map(a->a.getArrivalAsDouble())
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.collectingAndThen(
|
||||||
|
Collectors.toList(),
|
||||||
|
a -> (a.size() % 2 == 0) ? ((a.get(a.size() / 2 - 1) + a.get(a.size() / 2)) / 2) : (a.get(a.size() / 2))));
|
||||||
|
|
||||||
|
TTime arrivalTTime = TTime.ofMilliseconds((int)(medianArrival * 60 * 60 * 1000));
|
||||||
|
while(arrivalTTime.getMinute() % 5 != 0) {
|
||||||
|
arrivalTTime = arrivalTTime.add(new TTime(0,1));
|
||||||
|
}
|
||||||
|
arrivalTextField.valueProperty.setValue(arrivalTTime.toString().substring(0, 5));
|
||||||
|
wd.setArrivalHour(arrivalTTime.getHour());
|
||||||
|
wd.setArrivalMinute(arrivalTTime.getMinute());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wd.setArrivalHour(7);
|
||||||
|
wd.setArrivalMinute(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
int year = cal.get(Calendar.YEAR);
|
int year = cal.get(Calendar.YEAR);
|
||||||
int month = cal.get(Calendar.MONTH) + 1;
|
int month = cal.get(Calendar.MONTH) + 1;
|
||||||
int day = cal.get(Calendar.DAY_OF_MONTH);
|
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||||
wd = new WorkingDay();
|
|
||||||
wd.setId(WorkingDay.createId(year, month, day));
|
wd.setId(WorkingDay.createId(year, month, day));
|
||||||
wd.setYear(year);
|
wd.setYear(year);
|
||||||
wd.setMonth(month);
|
wd.setMonth(month);
|
||||||
wd.setDay(day);
|
wd.setDay(day);
|
||||||
wd.setArrivalHour(7);
|
wd.setOvertimeHour(0);
|
||||||
wd.setArrivalMinute(0);
|
wd.setOvertimeMinute(0);
|
||||||
wd.setOvertimeHour(0);
|
wd.setWorkingTimeInMinutes(480);
|
||||||
wd.setOvertimeMinute(0);
|
wd.setPauseTimeInMinutes(30);
|
||||||
wd.setWorkingTimeInMinutes(480);
|
wd.setNote("");
|
||||||
wd.setPauseTimeInMinutes(30);
|
wd.setTimeOff(false);
|
||||||
wd.setNote("");
|
|
||||||
wd.setTimeOff(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
workingDayRepository.update(wd);
|
|
||||||
|
|
||||||
System.out.println(wd);
|
workingDayRepository.update(wd);
|
||||||
|
|
||||||
File dbFile = new File(FileConstants.TC_DIRECTORY.getAbsolutePath() + "/" + "time-calc.sqlite3");
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
if(Math.random() > 0.999) {
|
if(Math.random() > 0.99) {
|
||||||
File dbFileBackup = new File(dbFile.getAbsolutePath() + ".backup." + DateFormats.DATE_TIME_FORMATTER_SHORT.format(new Date()).substring(0, 10) + ".sqlite3");
|
File dbFileBackup = new File(
|
||||||
if (dbFile.exists() && !dbFileBackup.exists()) {
|
FileConstants.DB_FILE.getAbsolutePath() + ".backup."
|
||||||
|
+ DateFormats.DATE_TIME_FORMATTER_SHORT
|
||||||
|
.format(new Date()).substring(0, 10)
|
||||||
|
+ ".sqlite3");
|
||||||
|
if (FileConstants.DB_FILE.exists() && !dbFileBackup.exists()) {
|
||||||
try {
|
try {
|
||||||
Files.copy(dbFile.toPath(), dbFileBackup.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(FileConstants.DB_FILE.toPath(),
|
||||||
|
dbFileBackup.toPath(),
|
||||||
|
StandardCopyOption.REPLACE_EXISTING);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(Math.random() > 0.9999) {
|
||||||
for(File file: FileConstants.TC_DIRECTORY.listFiles()) {
|
for(File file: FileConstants.TC_DIRECTORY.listFiles()) {
|
||||||
if(file.getName().startsWith(dbFile.getName() + ".backup")) {
|
if(file.getName().startsWith(FileConstants.DB_FILE.getName() + ".backup")) {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long diff = now - Files.getLastModifiedTime(file.toPath()).toMillis();
|
long diff = now - Files.getLastModifiedTime(file.toPath()).toMillis();
|
||||||
|
@ -17,6 +17,7 @@ public class FileConstants {
|
|||||||
public static final File FILE_WITHOUT_ANY_PROFILE
|
public static final File FILE_WITHOUT_ANY_PROFILE
|
||||||
= new File(TC_DIRECTORY, "timecalc.conf");
|
= new File(TC_DIRECTORY, "timecalc.conf");
|
||||||
public static final File JOKES_TXT = new File(TC_DIRECTORY, "time-calc-jokes.txt");
|
public static final File JOKES_TXT = new File(TC_DIRECTORY, "time-calc-jokes.txt");
|
||||||
|
public static final File DB_FILE = new File(FileConstants.TC_DIRECTORY.getAbsolutePath() + "/" + "time-calc.sqlite3");
|
||||||
|
|
||||||
private FileConstants() {
|
private FileConstants() {
|
||||||
//Not meant to be instantiated.
|
//Not meant to be instantiated.
|
||||||
|
@ -2,6 +2,7 @@ package org.nanoboot.utils.timecalc.utils.common;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
@ -20,6 +21,7 @@ public class TTime implements Comparable<TTime> {
|
|||||||
|
|
||||||
public static final TTime T_TIME_ONE_MINUTE = new TTime(0, 1);
|
public static final TTime T_TIME_ONE_MINUTE = new TTime(0, 1);
|
||||||
public static final TTime T_TIME_ONE_HOUR = new TTime(1,0);
|
public static final TTime T_TIME_ONE_HOUR = new TTime(1,0);
|
||||||
|
public static final TTime T_TIME_FIVE_MINUTES = new TTime(0,5);
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private boolean negative;
|
private boolean negative;
|
||||||
@ -100,6 +102,9 @@ public class TTime implements Comparable<TTime> {
|
|||||||
string = string.replace("-", "");
|
string = string.replace("-", "");
|
||||||
}
|
}
|
||||||
String[] array = string.split(":");
|
String[] array = string.split(":");
|
||||||
|
if(array.length < 2) {
|
||||||
|
throw new TimeCalcException("Wrong format of time: " + string);
|
||||||
|
}
|
||||||
this.hour = (negative ? (1) : 1) * Integer.valueOf(array[0]);
|
this.hour = (negative ? (1) : 1) * Integer.valueOf(array[0]);
|
||||||
this.minute = (negative ? (1) : 1) * Integer.valueOf(array[1]);
|
this.minute = (negative ? (1) : 1) * Integer.valueOf(array[1]);
|
||||||
this.second = array.length >= 3 ? ((negative ? (1) : 1) * Integer.valueOf(array[2])) : 0;
|
this.second = array.length >= 3 ? ((negative ? (1) : 1) * Integer.valueOf(array[2])) : 0;
|
||||||
@ -167,7 +172,7 @@ public class TTime implements Comparable<TTime> {
|
|||||||
public static int countDiffInMinutes(TTime startTime, TTime endTime) {
|
public static int countDiffInMinutes(TTime startTime, TTime endTime) {
|
||||||
return (endTime.getHour() * TTime.MINUTES_PER_HOUR + endTime
|
return (endTime.getHour() * TTime.MINUTES_PER_HOUR + endTime
|
||||||
.getMinute()) - (startTime.getHour() * TTime.MINUTES_PER_HOUR
|
.getMinute()) - (startTime.getHour() * TTime.MINUTES_PER_HOUR
|
||||||
+ startTime.getMinute());
|
+ startTime.getMinute());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TTime cloneInstance() {
|
public TTime cloneInstance() {
|
||||||
|
@ -199,7 +199,7 @@ Smileys can be colored or white-black (can be set in configuration)
|
|||||||
* CTRL + W - Decrease worknig time
|
* CTRL + W - Decrease worknig time
|
||||||
* SHIFT + P - Increase pause
|
* SHIFT + P - Increase pause
|
||||||
* CTRL + P - Decrease pause
|
* CTRL + P - Decrease pause
|
||||||
* SHIFT + C - Increase or decrease of time is change by 1 hour
|
* SHIFT + C - Increase or decrease of time is change by 5 minutes
|
||||||
* CTRL + C - Increase or decrease of time is change by 1 minute
|
* CTRL + C - Increase or decrease of time is change by 1 minute
|
||||||
* CTRL + E - Save arrival, overtime, working time, pause time and note
|
* CTRL + E - Save arrival, overtime, working time, pause time and note
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user