Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Wrong tooltip on data period tag (#2130)

Stanimirf6aa97496f34
diff --git a/src/renderer/components/TagContainer.tsx b/src/renderer/components/TagContainer.tsx
index e33c1c647..455adf212 100644
--- a/src/renderer/components/TagContainer.tsx
+++ b/src/renderer/components/TagContainer.tsx
@@ -25,7 +25,7 @@ import Tooltip from '-/components/Tooltip';
import { formatDateTime } from '@tagspaces/tagspaces-common/misc';
import { getTagColor, getTagTextColor } from '-/reducers/settings';
import { isGeoTag } from '-/utils/geo';
-import { isDateTimeTag, convertToDateTime, convertToDate } from '-/utils/dates';
+import { isDateTimeTag, convertToTimestamp } from '-/utils/dates';
import { TS } from '-/tagspaces.namespace';
import { getTagColors } from '-/services/taglibrary-utils';
import TagContainerMenu from '-/components/TagContainerMenu';
@@ -118,12 +118,25 @@ function TagContainer(props: Props) {
let tagTitle = ''; // tag.title;
if (isTagDate) {
let date;
- if (tag.title.length > 8) {
- date = new Date(convertToDateTime(tag.title)).getTime();
+ if (tag.title.includes('-')) {
+ const timeArr = tag.title.split('-');
+ if (parseInt(timeArr[0], 10) && parseInt(timeArr[1], 10)) {
+ const firstTime = convertToTimestamp(timeArr[0]);
+ const secondTime = convertToTimestamp(timeArr[1]);
+ const haveTime0 = timeArr[0].length > 8;
+ const haveTime1 = timeArr[1].length > 8;
+ tagTitle =
+ formatDateTime(firstTime, haveTime0) +
+ ' <-> ' +
+ formatDateTime(secondTime, haveTime1);
+ }
+ } else if (tag.title.length > 8) {
+ date = convertToTimestamp(tag.title); //new Date(convertToDateTime(tag.title)).getTime();
+ tagTitle = formatDateTime(date, true);
} else {
- date = new Date(convertToDate(tag.title)).getTime();
+ date = convertToTimestamp(tag.title); //new Date(convertToDate(tag.title)).getTime();
+ tagTitle = formatDateTime(date, false);
}
- tagTitle = formatDateTime(date, true);
}
if (tag.description) {
diff --git a/src/renderer/components/dialogs/EditEntryTagDialog.tsx b/src/renderer/components/dialogs/EditEntryTagDialog.tsx
index 8eb0d5330..a1b9020e3 100644
--- a/src/renderer/components/dialogs/EditEntryTagDialog.tsx
+++ b/src/renderer/components/dialogs/EditEntryTagDialog.tsx
@@ -105,7 +105,9 @@ function EditEntryTagDialog(props: Props) {
function onConfirm() {
if (handleValidation() && !haveError()) {
- const isNew = tag.functionality === 'geoTagging'; //path.includes(props.selectedTag.title);
+ const isNew =
+ tag.functionality === 'geoTagging' ||
+ tag.functionality === 'dateTagging'; //path.includes(props.selectedTag.title);
if (isNew) {
addTagsToEntry(tag.path, [{ ...tag, title }]);
} else {
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index 423063819..62e235cd8 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -634,7 +634,6 @@ export const TaggingActionsContextProvider = ({
delete tag.functionality;
delete tag.path;
delete tag.id;
-
const extractedTags: string[] = extractTags(
path,
tagDelimiter,
@@ -642,7 +641,8 @@ export const TaggingActionsContextProvider = ({
);
// TODO: Handle adding already added tags
if (extractedTags.includes(tag.title)) {
- // tag.type === 'plain') {
+ //tag.type === 'plain') {
+
const fileName = extractFileName(
path,
currentLocation?.getDirSeparator(),
diff --git a/src/renderer/utils/dates.ts b/src/renderer/utils/dates.ts
index 0de0d8a0d..06fad63b2 100644
--- a/src/renderer/utils/dates.ts
+++ b/src/renderer/utils/dates.ts
@@ -16,6 +16,8 @@
*
*/
+import { parse } from 'date-fns';
+
/** Returns true if the input is one of the following formats:
* 2015, 201402, 20220212, 20190230~12, 20190230~1245, 20190230~124612 */
export function isDateTimeTag(tagDate: string): boolean {
@@ -489,7 +491,49 @@ export function convertToDate(date: string) {
}
}
-export function convertToDateTime(dateTime: string) {
+export function convertToTimestamp(dateStr: string): number {
+ if (typeof dateStr !== 'string') {
+ throw new Error('Invalid date format. Please provide a date string.');
+ }
+
+ // Define possible date formats
+ const formats = [
+ 'yyyy',
+ 'yyyyMM',
+ 'yyyyMMdd',
+ 'yyyyMMdd~HHmmss',
+ 'yyyyMMdd-HHmmss',
+ 'yyyyMMdd HHmmss',
+ "yyyyMMdd'T'HHmmss",
+ 'yyyy-MM',
+ 'yyyy-MM-dd',
+ 'yyyy-MM-dd HH:mm:ss',
+ ];
+
+ // Try to parse the date string using each format
+ for (const format of formats) {
+ try {
+ const parsedDate = parse(dateStr, format, new Date());
+ const timestamp = parsedDate.getTime();
+ // Check if the parsed date is valid
+ if (!isNaN(timestamp)) {
+ return timestamp;
+ }
+ } catch (error) {
+ // Ignore parsing errors and try the next format
+ }
+ }
+
+ // If none of the formats worked, throw an error
+ //throw new Error('Invalid date string or format.' + dateStr);
+ console.log('Invalid date string or format.' + dateStr);
+ return new Date().getTime();
+}
+
+/**
+ * @deprecated use convertToTimestamp instead
+ */
+/*export function convertToDateTime(dateTime: string) {
const dateTimeRegExp =
/^\d\d\d\d-(00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/g;
const dateTimeWinRegExp =
@@ -556,7 +600,7 @@ export function convertToDateTime(dateTime: string) {
}
}
}
-}
+}*/
export function convertToDateRange(dateRange: string) {
const dateRangeRegExp =