Skip to content

Commit

Permalink
1.10.1 Task: added unspecified datetime for datetime values before th…
Browse files Browse the repository at this point in the history
…e introduction of the history
  • Loading branch information
Mikescher committed Oct 11, 2016
1 parent 005e33c commit 6c7e590
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 30 deletions.
3 changes: 3 additions & 0 deletions res/de/jClipCorn/gui/localization/locale.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CCDate.Month7 = Juli
CCDate.Month8 = August
CCDate.Month9 = September
CCDate.STRINGREP_EXTENDED = dddd, den dd.MMMM yyyy
CCDate.STRINGREP_UNSPEC = Unbekannter Zeitpunkt

CCLog.Error = Error
CCLog.Errors = Errors
Expand Down Expand Up @@ -328,6 +329,7 @@ CheckDatabaseDialog.Error.ERR_33 = Die Gesehen-Historie e
CheckDatabaseDialog.Error.ERR_34 = Die Gruppenliste enth\u00E4lt ung\u00FCltige Gruppen
CheckDatabaseDialog.Error.ERR_35 = Die interne Gruppenauflisting der Datenbank enth\u00E4lt Fehler
CheckDatabaseDialog.Error.ERR_36 = Zwei Elemente verweisen auf die gleiche Online Resource
CheckDatabaseDialog.Error.ERR_37 = Der Status ist Gesehen aber es existiert keine History
CheckDatabaseDialog.Errornames.ERR_01 = L\u00FCcke in Genres
CheckDatabaseDialog.Errornames.ERR_02 = Ung\u00FCltiges Genre
CheckDatabaseDialog.Errornames.ERR_03 = Falsche Dateigr\u00F6\u00DFe
Expand Down Expand Up @@ -363,6 +365,7 @@ CheckDatabaseDialog.Errornames.ERR_33 = Invalide Historie
CheckDatabaseDialog.Errornames.ERR_34 = Fehlergafte Gruppenliste
CheckDatabaseDialog.Errornames.ERR_35 = Invalide Gruppe
CheckDatabaseDialog.Errornames.ERR_36 = Doppelte Online-ID
CheckDatabaseDialog.Errornames.ERR_37 = Gesehen aber keine Historie
CheckDatabaseDialog.btnAutofix.text = Try to auto. fix problems
CheckDatabaseDialog.btnFixSelected.text = Fix Selected
CheckDatabaseDialog.btnValidate.text = Validate Database
Expand Down
3 changes: 3 additions & 0 deletions res/de/jClipCorn/gui/localization/locale_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CCDate.Month7 = Juli
CCDate.Month8 = August
CCDate.Month9 = September
CCDate.STRINGREP_EXTENDED = dddd, den dd.MMMM yyyy
CCDate.STRINGREP_UNSPEC = Unbekannter Zeitpunkt

CCLog.Error = Fehler
CCLog.Errors = Fehler
Expand Down Expand Up @@ -328,6 +329,7 @@ CheckDatabaseDialog.Error.ERR_33 = Die Gesehen-Historie e
CheckDatabaseDialog.Error.ERR_34 = Die Gruppenliste enth\u00E4lt ung\u00FCltige Gruppen
CheckDatabaseDialog.Error.ERR_35 = Die interne Gruppenauflisting der Datenbank enth\u00E4lt Fehler
CheckDatabaseDialog.Error.ERR_36 = Zwei Elemente verweisen auf die gleiche Online Resource
CheckDatabaseDialog.Error.ERR_37 = Der Status ist Gesehen aber es existiert keine History
CheckDatabaseDialog.Errornames.ERR_01 = L\u00FCcke in Genres
CheckDatabaseDialog.Errornames.ERR_02 = Ung\u00FCltiges Genre
CheckDatabaseDialog.Errornames.ERR_03 = Falsche Dateigr\u00F6\u00DFe
Expand Down Expand Up @@ -363,6 +365,7 @@ CheckDatabaseDialog.Errornames.ERR_33 = Invalide Historie
CheckDatabaseDialog.Errornames.ERR_34 = Fehlergafte Gruppenliste
CheckDatabaseDialog.Errornames.ERR_35 = Invalide Gruppe
CheckDatabaseDialog.Errornames.ERR_36 = Doppelte Online-ID
CheckDatabaseDialog.Errornames.ERR_37 = Gesehen aber keine Historie
CheckDatabaseDialog.btnAutofix.text = Versuche Probleme autom. zu l\u00F6sen
CheckDatabaseDialog.btnFixSelected.text = Markiertes Problem l\u00F6sen
CheckDatabaseDialog.btnValidate.text = \u00DCberpr\u00FCfe Datenbank
Expand Down
3 changes: 3 additions & 0 deletions res/de/jClipCorn/gui/localization/locale_dl_DL.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CCDate.Month7 = Juli
CCDate.Month8 = August
CCDate.Month9 = September
CCDate.STRINGREP_EXTENDED = dddd, den dd.MMMM yyyy
CCDate.STRINGREP_UNSPEC = Unbekannter Zeitpunkt

CCLog.Error = Error
CCLog.Errors = Errors
Expand Down Expand Up @@ -328,6 +329,7 @@ CheckDatabaseDialog.Error.ERR_33 = Die Gesehen-Historie e
CheckDatabaseDialog.Error.ERR_34 = Die Gruppenliste enth\u00E4lt ung\u00FCltige Gruppen
CheckDatabaseDialog.Error.ERR_35 = Die interne Gruppenauflisting der Datenbank enth\u00E4lt Fehler
CheckDatabaseDialog.Error.ERR_36 = Zwei Elemente verweisen auf die gleiche Online Resource
CheckDatabaseDialog.Error.ERR_37 = Der Status ist Gesehen aber es existiert keine History
CheckDatabaseDialog.Errornames.ERR_01 = L\u00FCcke in Genres
CheckDatabaseDialog.Errornames.ERR_02 = Ung\u00FCltiges Genre
CheckDatabaseDialog.Errornames.ERR_03 = Falsche Dateigr\u00F6\u00DFe
Expand Down Expand Up @@ -363,6 +365,7 @@ CheckDatabaseDialog.Errornames.ERR_33 = Invalide Historie
CheckDatabaseDialog.Errornames.ERR_34 = Fehlergafte Gruppenliste
CheckDatabaseDialog.Errornames.ERR_35 = Invalide Gruppe
CheckDatabaseDialog.Errornames.ERR_36 = Doppelte Online-ID
CheckDatabaseDialog.Errornames.ERR_37 = Gesehen aber keine Historie
CheckDatabaseDialog.btnAutofix.text = Try to auto. fix problems
CheckDatabaseDialog.btnFixSelected.text = Fix Selected
CheckDatabaseDialog.btnValidate.text = Validate Database
Expand Down
3 changes: 3 additions & 0 deletions res/de/jClipCorn/gui/localization/locale_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CCDate.Month7 = July
CCDate.Month8 = August
CCDate.Month9 = September
CCDate.STRINGREP_EXTENDED = dddd, the dd.MMMM yyyy
CCDate.STRINGREP_UNSPEC = Unknown Datetime

CCLog.Error = Error
CCLog.Errors = Errors
Expand Down Expand Up @@ -328,6 +329,7 @@ CheckDatabaseDialog.Error.ERR_33 = The viewed-history con
CheckDatabaseDialog.Error.ERR_34 = The groulist contains invalid groups
CheckDatabaseDialog.Error.ERR_35 = The internal group datastructure of this database contains inconsistencies
CheckDatabaseDialog.Error.ERR_36 = Two different elements point to the same online ID
CheckDatabaseDialog.Error.ERR_37 = The element is viewed but the viewed-history is empty
CheckDatabaseDialog.Errornames.ERR_01 = Gap in Genres
CheckDatabaseDialog.Errornames.ERR_02 = Wrong Genre-ID
CheckDatabaseDialog.Errornames.ERR_03 = Incorrect File Size
Expand Down Expand Up @@ -363,6 +365,7 @@ CheckDatabaseDialog.Errornames.ERR_33 = Invalid history
CheckDatabaseDialog.Errornames.ERR_34 = Invalid grouplist
CheckDatabaseDialog.Errornames.ERR_35 = Invalid group
CheckDatabaseDialog.Errornames.ERR_36 = Duplicate Online-ID
CheckDatabaseDialog.Errornames.ERR_37 = Viewed but empty history
CheckDatabaseDialog.btnAutofix.text = Try to auto. fix problems
CheckDatabaseDialog.btnFixSelected.text = Fix Selected
CheckDatabaseDialog.btnValidate.text = Validate Database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public CCDateTimeList(CCDateTime datetime) {
public boolean isEmpty() {
return list.isEmpty();
}

public boolean isEmptyOrOnlyUnspecified() {
for (CCDateTime dt : list) if (! dt.isUnspecifiedDateTime()) return false;

return true;
}

public boolean any() {
return !list.isEmpty();
Expand Down Expand Up @@ -94,25 +100,43 @@ public static CCDateTimeList create(CCDate date) {
}

public CCDateTime getFirstOrInvalid() {
return isEmpty() ? CCDateTime.getMinimumDateTime() : list.get(0);
List<CCDateTime> specList = getSpecifiedList();

if (specList.isEmpty()) return CCDateTime.getMinimumDateTime();

return specList.get(0);
}

public CCDateTime getLastOrInvalid() {
return isEmpty() ? CCDateTime.getMinimumDateTime() : list.get(count() - 1);
List<CCDateTime> specList = getSpecifiedList();

if (specList.isEmpty()) return CCDateTime.getMinimumDateTime();

return specList.get(specList.size() - 1);
}

public CCDate getLastDateOrInvalid() {
return isEmpty() ? CCDate.getMinimumDate() : list.get(count() - 1).date;
List<CCDate> specList = getSpecifiedDateList();

if (specList.isEmpty()) return CCDate.getMinimumDate();

return specList.get(specList.size() - 1);
}

public CCDate getFirstDateOrInvalid() {
return isEmpty() ? CCDate.getMinimumDate() : list.get(0).date;
List<CCDate> specList = getSpecifiedDateList();

if (specList.isEmpty()) return CCDate.getMinimumDate();

return specList.get(0);
}

public CCDate getAverageDateOrInvalid() {
if (isEmpty()) return CCDate.getMinimumDate();
List<CCDate> specList = getSpecifiedDateList();

if (specList.isEmpty()) return CCDate.getMinimumDate();

return CCDate.getAverageDate(getDateList());
return CCDate.getAverageDate(specList);
}

public boolean contains(CCDateTime time) {
Expand Down Expand Up @@ -152,13 +176,33 @@ public List<CCDate> getDateList() {
}
return l;
}

/*
* List of dates
* (dates can be not unique (cause of different times)
*/
public List<CCDate> getSpecifiedDateList() {
List<CCDate> l = new ArrayList<>();
for (CCDateTime dt : list) {
if (! dt.isUnspecifiedDateTime()) l.add(dt.date);
}
return l;
}

public List<CCDateTime> getSpecifiedList() {
List<CCDateTime> l = new ArrayList<>();
for (CCDateTime dt : list) {
if (! dt.isUnspecifiedDateTime()) l.add(dt);
}
return l;
}

public String getHTMLListFormatted() {
return getHTMLListFormatted(0);
}

public String getHTMLListFormatted(int hiddenHack) {
if (isEmpty()) return "";
if (isEmptyOrOnlyUnspecified()) return "";

StringBuilder b = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ public class DatabaseErrorType {
public static DatabaseErrorType ERROR_INVALID_GROUPLIST = new DatabaseErrorType(34);
public static DatabaseErrorType ERROR_INVALID_GROUP = new DatabaseErrorType(35);
public static DatabaseErrorType ERROR_DUPLICATE_REF = new DatabaseErrorType(36);

public static DatabaseErrorType ERROR_VIEWED_BUT_NO_HISTORY = new DatabaseErrorType(37);

private final int type;
private int count = 0;

public DatabaseErrorType(int ptype) {
this.type = ptype;
}

public DatabaseErrorType(DatabaseErrorType ptype) {
this.type = ptype.getType();
this.count = ptype.count;
Expand All @@ -55,24 +56,24 @@ public DatabaseErrorType(DatabaseErrorType ptype) {
public int getType() {
return type;
}

@Override
public boolean equals(Object e) {
return e instanceof DatabaseErrorType && ((DatabaseErrorType)e).getType() == this.getType();
return e instanceof DatabaseErrorType && ((DatabaseErrorType) e).getType() == this.getType();
}

@Override
public int hashCode() {
return type;
}

@SuppressWarnings("nls")
@Override
public String toString() {
if (count == 0) {
return LocaleBundle.getString(String.format("CheckDatabaseDialog.Errornames.ERR_%02d", type));
return LocaleBundle.getString(String.format("CheckDatabaseDialog.Errornames.ERR_%02d", type));
} else {
return LocaleBundle.getString(String.format("CheckDatabaseDialog.Errornames.ERR_%02d", type)) + " (" + count + ")";
return LocaleBundle.getString(String.format("CheckDatabaseDialog.Errornames.ERR_%02d", type)) + " (" + count + ")";
}
}

Expand Down Expand Up @@ -100,28 +101,28 @@ public boolean isAutoFixable() {
} else if (equals(ERROR_INVALID_CHARS_IN_PATH)) {
return true;
}

return false;
}

public void incCount() {
count++;
}

public void setCount(int c) {
count = c;
}

public int getCount() {
return count;
}

public DatabaseErrorType copy(int pcount) {
DatabaseErrorType det = new DatabaseErrorType(this);
det.setCount(pcount);
return det;
}

public DatabaseErrorType copy() {
return new DatabaseErrorType(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ private static void validateEpisode(List<DatabaseError> e, CCEpisode episode) {
if (!episode.isViewed() && !episode.getViewedHistory().isEmpty()) {
e.add(DatabaseError.createSingle(DatabaseErrorType.ERROR_HISTORY_BUT_UNVIEWED, episode));
}

// ###############################################
// Viewed but no history
// ###############################################

if (episode.isViewed() && episode.getViewedHistory().isEmpty()) {
e.add(DatabaseError.createSingle(DatabaseErrorType.ERROR_VIEWED_BUT_NO_HISTORY, episode));
}

// ###############################################
// History is invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ public void actionPerformed(ActionEvent e) {
@Override
public void valueChanged(ListSelectionEvent e) {
if (list.getSelectedIndex() >= 0) {
edAddDateTime.setValue(list.getSelectedValue());
if (list.getSelectedValue().isUnspecifiedDateTime())
edAddDateTime.setValue(CCDateTime.getCurrentDateTime());
else
edAddDateTime.setValue(list.getSelectedValue());
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import de.jClipCorn.gui.localization.LocaleBundle;
import de.jClipCorn.gui.log.CCLog;
import de.jClipCorn.util.datetime.CCDateTime;
import de.jClipCorn.util.exceptions.CCFormatException;
Expand Down Expand Up @@ -62,7 +63,9 @@ public void commitEdit() {
String text = tf.getText();

try {
if (CCDateTime.testparse(text, CCDateTime.STRINGREP_SIMPLE)) {
if (text.equalsIgnoreCase(CCDateTime.UNSPECIFIED_REPRESENTATION) || text.equalsIgnoreCase(LocaleBundle.getString("CCDate.STRINGREP_UNSPEC"))) { //$NON-NLS-1$
owner.getModel().setValue(CCDateTime.getUnspecified());
} else if (CCDateTime.testparse(text, CCDateTime.STRINGREP_SIMPLE)) {
owner.getModel().setValue(CCDateTime.parse(text, CCDateTime.STRINGREP_SIMPLE));
} else if (CCDateTime.testparse(text, CCDateTime.STRINGREP_SIMPLESHORT)) {
owner.getModel().setValue(CCDateTime.parse(text, CCDateTime.STRINGREP_SIMPLESHORT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public TableDateListRenderer() {
@Override
public void setValue(Object value) {
CCDateTimeList d = ((CCDateTimeList)value);
if (d.isEmpty()) {
if (d.isEmptyOrOnlyUnspecified()) {
setText(" - "); //$NON-NLS-1$
} else {
switch (CCProperties.getInstance().PROP_SERIES_DISPLAYED_DATE.getValue()) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/de/jClipCorn/util/datetime/CCDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class CCDate implements Comparable<CCDate>, StringSpecSupplier {
private static final CCDate DATE_MIN = new CCDate(1, 1, YEAR_MIN);
private static final CCDate DATE_MAX = new CCDate(31, 12, YEAR_MAX);
public static final String MIN_SQL = DATE_MIN.getSQLStringRepresentation();
private static final CCDate UNSPECIFIED = new CCDate(99, 99, 99);

private static HashSet<Character> stringSpecifier = null; // { 'y', 'M', 'd' }

Expand Down Expand Up @@ -120,6 +121,10 @@ public static CCDate getMaximumDate() { //Not really Maximum - just extreme high
return DATE_MAX;
}

public static CCDate getUnspecified() {
return UNSPECIFIED;
}

public String getMonthName() {
return MONTHNAMES[month];
}
Expand Down Expand Up @@ -423,7 +428,7 @@ public int getDayDifferenceTo(CCDate other) {

@Override
public String toString() {
return getSimpleStringRepresentation();
return "<CCDate>:" + getSQLStringRepresentation(); //$NON-NLS-1$
}

public int compare(CCDate other) {
Expand Down Expand Up @@ -509,6 +514,10 @@ public static int compare(CCDate o1, CCDate o2) {
public boolean isMinimum() {
return 1 == getDay() && 1 == getMonth() && YEAR_MIN == getYear();
}

public boolean isUnspecifiedDate() {
return 99 == getDay() && 99 == getMonth() && 99 == getYear();
}

public static CCDate getMinDate(List<CCDate> datelist) {
CCDate min = getMaximumDate();
Expand Down Expand Up @@ -563,6 +572,8 @@ public long asMilliseconds() {
/// This checks _not_ for unset dates (1.1.1900)
/// This checks only for really invalid dates (eg 40.13.1800)
public boolean isValidDate() {
if (isUnspecifiedDate()) return true;

if (! (year >= YEAR_MIN)) {
return false;
}
Expand Down
Loading

0 comments on commit 6c7e590

Please sign in to comment.