Skip to content

Commit

Permalink
remove longFormatDate
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis committed Aug 1, 2024
1 parent 8f1f3fd commit 336a8fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
4 changes: 4 additions & 0 deletions scripts/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ if (appConfig.view.timeformat == null) {
appConfig.view.timeformat = 'hh:mm'; // 24h format
}

if (appConfig.longDateFormat == null) {
appConfig.longDateFormat = 'LLL';
}

if (appConfig.ui == null) {
appConfig.ui = {};

Expand Down
4 changes: 2 additions & 2 deletions scripts/core/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {gettext} from 'core/utils';
import moment from 'moment-timezone';
import {appConfig} from 'appConfig';
import {IArticle} from 'superdesk-api';
import {formatDate, longFormatDate} from 'core/get-superdesk-api-implementation';
import {formatDate} from 'core/get-superdesk-api-implementation';

const ISO_DATE_FORMAT = 'YYYY-MM-DD';
const ISO_WEEK_FORMAT = 'YYYY-W';
Expand Down Expand Up @@ -136,7 +136,7 @@ export function scheduledFormat(__item: IArticle): {short: string, long: string}

return {
short: short,
long: longFormatDate(datetime.moment),
long: formatDate(datetime.moment, {longFormat: true}),
};
}

Expand Down
31 changes: 9 additions & 22 deletions scripts/core/get-superdesk-api-implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,24 @@ export function isArticleLockedInCurrentSession(article: IArticle): boolean {
return ng.get('lock').isLockedInCurrentSession(article);
}

export const formatDate = (date: Date | string | moment.Moment, timezoneId?: string): string => {
export const formatDate = (
date: Date | string | moment.Moment,
options?: {timezoneId?: string; longFormat?:boolean},
): string => {
const momentDate = moment.isMoment(date) === true ? date as moment.Moment : moment(date);
const dateFormat = options.longFormat === true ? appConfig.longDateFormat : appConfig.view.dateformat;

if (timezoneId != null) {
if (options.timezoneId != null) {
return momentDate
.tz(timezoneId)
.format(appConfig.view.dateformat);
.tz(options.timezoneId)
.format(dateFormat);
} else {
const timezone: 'browser' | 'server' = appConfig.view.timezone ?? 'browser';
const keepLocalTime = timezone === 'browser';

return momentDate
.tz(appConfig.default_timezone, keepLocalTime)
.format(appConfig.view.dateformat);
.format(dateFormat);
}
};

Expand All @@ -252,23 +256,6 @@ export const formatDateTime = (date: Date, timezoneId?: string) => {
}
};

export const longFormatDate = (date: Date | string | moment.Moment, timezoneId?: string): string => {
const momentDate = moment.isMoment(date) === true ? date as moment.Moment : moment(date);

if (timezoneId != null) {
return momentDate
.tz(timezoneId)
.format(appConfig.view.dateformat + ' ' + appConfig.view.timeformat);
} else {
const timezone: 'browser' | 'server' = appConfig.view.timezone ?? 'browser';
const keepLocalTime = timezone === 'browser';

return momentDate
.tz(appConfig.default_timezone, keepLocalTime)
.format(appConfig.longDateFormat || 'LLL');
}
};

export function dateToServerString(date: Date) {
return date.toISOString().slice(0, 19) + '+0000';
}
Expand Down

0 comments on commit 336a8fb

Please sign in to comment.