Skip to content

Commit

Permalink
Fix invalid date format (#6234)
Browse files Browse the repository at this point in the history
* Fix redundant date format

* Add changelog
  • Loading branch information
asteriscos authored Dec 19, 2023
1 parent c046cc5 commit 52e8096
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed exception in IT-Hygiene when an agent doesn't have policies [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177)
- Fixed exception in Inventory when agents don't have S.O. information [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177)
- Fixed pinned agent state in URL [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177)
- Fixed invalid date format in about and agent views [#6234](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6234)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const AgentsTable = compose(
/>
</span>
),
render: dateAdd => formatUIDate(dateAdd),
sortable: true,
show: false,
searchable: false,
Expand All @@ -250,6 +251,7 @@ export const AgentsTable = compose(
/>
</span>
),
render: lastKeepAlive => formatUIDate(lastKeepAlive),
sortable: true,
show: false,
searchable: false,
Expand Down Expand Up @@ -334,12 +336,6 @@ export const AgentsTable = compose(
return {
...item,
...(item.ip ? { ip: item.ip } : { ip: '-' }),
...(typeof item.dateAdd === 'string'
? { dateAdd: formatUIDate(item.dateAdd) }
: { dateAdd: '-' }),
...(typeof item.lastKeepAlive === 'string'
? { lastKeepAlive: formatUIDate(item.lastKeepAlive) }
: { lastKeepAlive: '-' }),
...(item.node_name !== 'unknown'
? { node_name: item.node_name }
: { node_name: '-' }),
Expand Down
2 changes: 1 addition & 1 deletion plugins/main/public/controllers/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class SettingsController {
const response = data.data.data;
this.appInfo = {
'app-version': response['app-version'],
installationDate: formatUIDate(response['installationDate']),
installationDate: response['installationDate'],
revision: response['revision'],
};

Expand Down
9 changes: 6 additions & 3 deletions plugins/main/public/react-services/time-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
import moment from 'moment-timezone';
import { getUiSettings } from '../kibana-services';

export const formatUIDate = (date) => {
export const formatUIDate = date => {
if (typeof date !== 'string') {
return '-';
}
const dateFormat = getUiSettings().get('dateFormat');
const timezone = getTimeZone();
const momentDate = moment(date);
momentDate.tz(timezone);
return momentDate.format(dateFormat);
}
};
const getTimeZone = () => {
const dateFormatTZ = getUiSettings().get('dateFormat:tz');
const detectedTimezone = moment.tz.guess();
return dateFormatTZ === 'Browser' ? detectedTimezone : dateFormatTZ;
}
};
3 changes: 3 additions & 0 deletions plugins/wazuh-core/public/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import moment from 'moment-timezone';
import { getUiSettings } from '../plugin-services';

export const formatUIDate = (date: Date) => {
if (typeof date !== 'string') {
return '-';
}
const dateFormat = getUiSettings().get('dateFormat');
const timezone = getTimeZone();
const momentDate = moment(date);
Expand Down

0 comments on commit 52e8096

Please sign in to comment.