Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions searchlib/components/AppInfo/AppInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import React from 'react';
import getInfo from '@eeacms/search/lib/getIndexInfo';
import { useAtom } from 'jotai';
import { DateTime } from 'luxon';
// import { DateTime } from 'luxon';
import { indexMetadataAtom, hasRequestAtom } from './state';

const formatDate = (date) => {
return date.toLocaleString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
timeZoneName: 'short',
});
};

function AppInfo({ appConfig, ...rest }) {
const { app_name, app_version } = appConfig;
const hostname = window.runtimeConfig?.HOSTNAME || 'localhost';
// const hostname = window.runtimeConfig?.HOSTNAME || 'localhost';

const [indexMetadata, setIndexMetadata] = useAtom(indexMetadataAtom);
const [hasRequest, setHasRequest] = useAtom(hasRequestAtom);
Expand All @@ -19,7 +32,7 @@ function AppInfo({ appConfig, ...rest }) {
}
if (!indexMetadata) {
getInfo(appConfig).then((response) => {
setIndexMetadata(response.toLocaleString(DateTime.DATETIME_FULL) || '');
setIndexMetadata(response ? formatDate(response) : '');
});
}
}, [appConfig, indexMetadata, setIndexMetadata, hasRequest, setHasRequest]);
Expand Down
43 changes: 33 additions & 10 deletions searchlib/components/DateTime/DateTime.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import { DateTime } from 'luxon';
// import { DateTime } from 'luxon';
//
// const FormatDateTime = (props) => {
// const { value, format = 'DATE_SHORT' } = props;
//
// if (value === null){
// return null;
// }
// const dt = value
// ? value.isLuxonDateTime
// ? value
// : DateTime.fromISO(value)
// : DateTime.local();
//
// return format === 'DATE_MED'
// ? dt.toFormat('d MMM yyyy')
// : dt.toLocaleString(DateTime[format]);
// };
//
// export default FormatDateTime;

const FormatDateTime = (props) => {
const { value, format = 'DATE_SHORT' } = props;

if (value === null){
if (value === null) {
return null;
}
const dt = value
? value.isLuxonDateTime
? value
: DateTime.fromISO(value)
: DateTime.local();

return format === 'DATE_MED'
? dt.toFormat('d MMM yyyy')
: dt.toLocaleString(DateTime[format]);
const dt = value instanceof Date ? value : new Date(value);

const formatOptions = {
DATE_SHORT: { year: 'numeric', month: 'short', day: 'numeric' },
DATE_MED: { day: 'numeric', month: 'short', year: 'numeric' },
};

if (format === 'DATE_MED') {
return dt.toLocaleDateString('en-US', formatOptions.DATE_MED);
} else {
return dt.toLocaleDateString('en-US', formatOptions.DATE_SHORT);
}
};

export default FormatDateTime;
8 changes: 5 additions & 3 deletions searchlib/lib/getIndexInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import superagent from 'superagent';
import { DateTime } from 'luxon';
// import { DateTime } from 'luxon';

function trim_slash(text) {
return text.replace(/^\/+|\/+$/g, '');
Expand Down Expand Up @@ -51,10 +51,12 @@ export default async function getInfo(appConfig) {
update_ts = aliases[0].substring(11);
}

const dt = DateTime.fromMillis(parseInt(update_ts));
// const dt = DateTime.fromMillis(parseInt(update_ts));
const dt = new Date(parseInt(update_ts));
return dt;
} catch {
console.log('info', info);
// eslint-disable-next-line no-console
console.warn('Error in parsing index settings', info);
return '';
}
}
46 changes: 37 additions & 9 deletions searchlib/lib/models.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import registry from '@eeacms/search/registry';
import { DateTime } from 'luxon';
// import { DateTime } from 'luxon';

function getHighlight(hit, fieldName) {
if (
Expand Down Expand Up @@ -116,33 +116,61 @@ export class BasicModel {
}

export class ResultModel extends BasicModel {
// get daysSinceIssued() {
// const raw = this._result['issued']?.raw;
// const issued = raw ? DateTime.fromISO(raw) : DateTime.local();
// const res = DateTime.local().diff(issued, 'days').as('days');
// return res;
// }

get daysSinceIssued() {
const raw = this._result['issued']?.raw;
const issued = raw ? DateTime.fromISO(raw) : DateTime.local();
const res = DateTime.local().diff(issued, 'days').as('days');
return res;
const issuedDate = raw ? new Date(raw) : new Date();
const currentDate = new Date();

const diffInTime = currentDate.getTime() - issuedDate.getTime();
const diffInDays = diffInTime / (1000 * 3600 * 24);
return diffInDays;
}

get id() {
return this.id?.raw;
}

// get isNew() {
// const raw = this._result['issued']?.raw;
// const issued = raw ? DateTime.fromISO(raw) : DateTime.local();
// const res = DateTime.local().diff(issued, 'days').as('days');
//
// return res < 30;
// }

get isNew() {
const raw = this._result['issued']?.raw;
const issued = raw ? DateTime.fromISO(raw) : DateTime.local();
const res = DateTime.local().diff(issued, 'days').as('days');
const issuedDate = raw ? new Date(raw) : new Date();
const currentDate = new Date();

return res < 30;
const diffInTime = currentDate.getTime() - issuedDate.getTime();
const diffInDays = diffInTime / (1000 * 3600 * 24);
return diffInDays < 30;
}

// get issued() {
// const raw = this._result['issued']?.raw;
// return raw ? DateTime.fromISO(raw) : null;
// }
get issued() {
const raw = this._result['issued']?.raw;
return raw ? DateTime.fromISO(raw) : null;
return raw ? new Date(raw) : null;
}

// get expires() {
// const raw = this._result['expires']?.raw;
// return raw ? DateTime.fromISO(raw) : null;
// }
get expires() {
const raw = this._result['expires']?.raw;
return raw ? DateTime.fromISO(raw) : null;
return raw ? new Date(raw) : null;
}

// get isExpired() {
Expand Down