diff --git a/scripts/core/get-superdesk-api-implementation.tsx b/scripts/core/get-superdesk-api-implementation.tsx index 87f970aa7b..3f506a63a2 100644 --- a/scripts/core/get-superdesk-api-implementation.tsx +++ b/scripts/core/get-superdesk-api-implementation.tsx @@ -489,15 +489,33 @@ export function getSuperdeskApiImplementation( gettext: (message, params) => gettext(message, params), gettextPlural: (count, singular, plural, params) => gettextPlural(count, singular, plural, params), formatDate: formatDate, - formatDateTime: (date: Date) => { - return moment(date) - .tz(appConfig.default_timezone) - .format(appConfig.view.dateformat + ' ' + appConfig.view.timeformat); + formatDateTime: (date: Date, timezoneId?: string) => { + if (timezoneId != null) { + return moment(date) + .tz(timezoneId) + .format(appConfig.view.dateformat + ' ' + appConfig.view.timeformat); + } else { + const timezone: 'browser' | 'server' = appConfig.view.timezone ?? 'browser'; + const keepLocalTime = timezone === 'browser'; + + return moment(date) + .tz(appConfig.default_timezone, keepLocalTime) + .format(appConfig.view.dateformat + ' ' + appConfig.view.timeformat); + } }, - longFormatDateTime: (date: Date | string) => { - return moment(date) - .tz(appConfig.default_timezone) - .format(appConfig.longDateFormat || 'LLL'); + longFormatDateTime: (date: Date | string, timezoneId?: string) => { + if (timezoneId != null) { + return moment(date) + .tz(timezoneId) + .format(appConfig.view.dateformat + ' ' + appConfig.view.timeformat); + } else { + const timezone: 'browser' | 'server' = appConfig.view.timezone ?? 'browser'; + const keepLocalTime = timezone === 'browser'; + + return moment(date) + .tz(appConfig.default_timezone, keepLocalTime) + .format(appConfig.longDateFormat || 'LLL'); + } }, getRelativeOrAbsoluteDateTime: getRelativeOrAbsoluteDateTime, }, diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index d10018d5bb..17bee2f0fa 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -3050,8 +3050,8 @@ declare module 'superdesk-api' { gettext(message: string, params?: {[placeholder: string]: string | number | React.ComponentType}): string; gettextPlural(count: number, singular: string, plural: string, params?: {[placeholder: string]: string | number | React.ComponentType}): string; formatDate(date: Date | string): string; - formatDateTime(date: Date): string; - longFormatDateTime(date: Date | string): string; + formatDateTime(date: Date, timezoneId?: string): string; + longFormatDateTime(date: Date | string, timezoneId?: string): string; getRelativeOrAbsoluteDateTime( datetimeString: string, format: string, @@ -3323,6 +3323,9 @@ declare module 'superdesk-api' { view: { dateformat: string; // a combination of YYYY, MM, and DD with a custom separator e.g. 'MM/DD/YYYY' timeformat: string; + + // determines whether browser or server timezone is used for outputting date and time in user interface + timezone?: 'browser' | 'server'; // defaults to browser }; user: { sign_off_mapping?: string;