From ab5721cb5c63ba855e470ea77d2505ffaf8dffa6 Mon Sep 17 00:00:00 2001 From: dzonidoo Date: Mon, 5 Aug 2024 14:07:51 +0200 Subject: [PATCH] changes after review --- scripts/appConfig.ts | 4 ++-- scripts/apps/archive/services/ArchiveService.ts | 5 +++-- .../authoring/directives/AuthoringHeaderDirective.ts | 4 ++-- scripts/apps/search/components/fields/embargo.tsx | 4 ++-- scripts/apps/search/components/fields/state.tsx | 5 ++--- scripts/apps/search/components/fields/used.tsx | 4 ++-- scripts/core/datetime/datetime.ts | 5 +---- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/scripts/appConfig.ts b/scripts/appConfig.ts index 7127dd96c5..1a8b8356a6 100644 --- a/scripts/appConfig.ts +++ b/scripts/appConfig.ts @@ -13,11 +13,11 @@ if (appConfig.shortTimeFormat == null) { } if (appConfig.view.dateformat == null) { - appConfig.view.dateformat = 'MM/DD'; // 24h format + appConfig.view.dateformat = 'MM/DD'; } if (appConfig.view.timeformat == null) { - appConfig.view.timeformat = 'hh:mm'; // 24h format + appConfig.view.timeformat = 'hh:mm'; } if (appConfig.longDateFormat == null) { diff --git a/scripts/apps/archive/services/ArchiveService.ts b/scripts/apps/archive/services/ArchiveService.ts index da7ff210de..c8a20bda20 100644 --- a/scripts/apps/archive/services/ArchiveService.ts +++ b/scripts/apps/archive/services/ArchiveService.ts @@ -1,6 +1,6 @@ import _ from 'lodash'; import moment from 'moment'; -import {formatDate} from 'core/get-superdesk-api-implementation'; +import {appConfig} from 'appConfig'; ArchiveService.$inject = ['desks', 'session', 'api', '$q', 'search', '$location']; export function ArchiveService(desks, session, api, $q, search, $location) { @@ -81,7 +81,8 @@ export function ArchiveService(desks, session, api, $q, search, $location) { * @return {Object} the list of archive items */ this.getRelatedItems = function(item, fromDateTime) { - var beforeDateTime = formatDate(fromDateTime || moment().subtract(1, 'days')); + var beforeDateTime = fromDateTime || moment().subtract(1, 'days') + .format(appConfig.view.dateformat); var params: any = {}; params.q = 'slugline.phrase:"' + _.trim(item.slugline) + '"'; // exact match diff --git a/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts b/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts index 02355b4a23..29758a9234 100644 --- a/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts +++ b/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts @@ -10,7 +10,6 @@ import {translateArticleType, gettext} from 'core/utils'; import {IArticle} from 'superdesk-api'; import {slideUpDown} from 'core/ui/slide-up-down'; import {runBeforeUpdateMiddlware} from '../services/authoring-helpers'; -import {formatDate} from 'core/get-superdesk-api-implementation'; AuthoringHeaderDirective.$inject = [ 'api', @@ -195,7 +194,8 @@ export function AuthoringHeaderDirective( scope.missing_link = false; if (scope.item.slugline && scope.item.type === 'text') { // get the midnight based on the default timezone not the user timezone. - var fromDateTime = formatDate(moment()); + var fromDateTime = moment().tz(appConfig.default_timezone) + .format(appConfig.view.dateformat); archiveService.getRelatedItems(scope.item, fromDateTime) .then((items) => { diff --git a/scripts/apps/search/components/fields/embargo.tsx b/scripts/apps/search/components/fields/embargo.tsx index 483b6b87b1..a5ddcbd469 100644 --- a/scripts/apps/search/components/fields/embargo.tsx +++ b/scripts/apps/search/components/fields/embargo.tsx @@ -1,8 +1,8 @@ import React from 'react'; import moment from 'moment'; import {gettext} from 'core/utils'; -import {longFormat} from 'core/datetime/datetime'; import {IPropsItemListInfo} from '../ListItemInfo'; +import {formatDate} from 'core/get-superdesk-api-implementation'; class EmbargoComponent extends React.PureComponent { render() { @@ -23,7 +23,7 @@ class EmbargoComponent extends React.PureComponent { key="embargo" className="state-label state_embargo" title={embargoed != null ? ( - gettext('Embargo until {{date}}', {date: longFormat(embargoed)}) + gettext('Embargo until {{date}}', {date: formatDate(embargoed, {longFormat: true})}) ) : ( gettext('Embargo: {{text}}', {text: embargoedText}) )} diff --git a/scripts/apps/search/components/fields/state.tsx b/scripts/apps/search/components/fields/state.tsx index 8abc16ef6c..21d80e416c 100644 --- a/scripts/apps/search/components/fields/state.tsx +++ b/scripts/apps/search/components/fields/state.tsx @@ -1,10 +1,9 @@ import React from 'react'; import {gettext} from 'core/utils'; import {IPropsItemListInfo} from '../ListItemInfo'; -import {longFormat} from 'core/datetime/datetime'; import {assertNever} from 'core/helpers/typescript-helpers'; import {ITEM_STATE} from 'apps/search/interfaces'; -import {openArticle} from 'core/get-superdesk-api-implementation'; +import {formatDate, openArticle} from 'core/get-superdesk-api-implementation'; export function getStateLabel(itemState: ITEM_STATE) { switch (itemState) { @@ -43,7 +42,7 @@ export class StateComponent extends React.Component { label: boolean = false; @@ -9,7 +9,7 @@ export class Used extends React.PureComponent { const item = this.props.item; if (item.used) { - const title = item.used_updated ? longFormat(item.used_updated) : null; + const title = item.used_updated ? formatDate(item.used_updated, {longFormat: true}) : null; return (
diff --git a/scripts/core/datetime/datetime.ts b/scripts/core/datetime/datetime.ts index 99709e6722..91f4af2967 100644 --- a/scripts/core/datetime/datetime.ts +++ b/scripts/core/datetime/datetime.ts @@ -21,9 +21,6 @@ const SERVER_FORMAT = 'YYYY-MM-DDTHH:mm:ssZZ'; * * @param {String} d iso format datetime */ -export function longFormat(d: string | moment.Moment): string { - return moment(d).format(LONG_FORMAT); -} export function serverFormat(d: string | moment.Moment): string { return moment(d).utc().format(SERVER_FORMAT); @@ -165,7 +162,7 @@ function DateTimeService() { return m.format(DATE_FORMAT); }; - this.longFormat = longFormat; + this.longFormat = (date) => formatDate(date, {longFormat: true}); } DateTimeHelperService.$inject = [];