Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix publish schedule time picker #4355

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {IArticle} from 'superdesk-api';
import {gettext, toServerDateFormat} from 'core/utils';
import {fromServerDateFormat, gettext, toServerDateFormat} from 'core/utils';
import {DateTimePicker} from 'core/ui/components/date-time-picker';
import {appConfig} from 'appConfig';
import {ToggleBox} from 'superdesk-ui-framework/react';
Expand All @@ -17,10 +17,10 @@ export interface IPublishingDateOptions {
export function getInitialPublishingDateOptions(items: Array<IArticle>): IPublishingDateOptions {
return {
embargo: items.length === 1 && items[0].embargo != null
? new Date(items[0].embargo) ?? null
? fromServerDateFormat(items[0].embargo) ?? null
: null,
publishSchedule: items.length === 1 && items[0].publish_schedule != null
? new Date(items[0].publish_schedule) ?? null
? fromServerDateFormat(items[0].publish_schedule) ?? null
: null,
timeZone: items.length === 1 ? items[0].schedule_settings?.time_zone ?? null : null,
};
Expand Down
10 changes: 9 additions & 1 deletion scripts/core/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {appConfig, getUserInterfaceLanguage} from 'appConfig';
import {IVocabularyItem, IArticle, IBaseRestApiResponse, ILockInfo} from 'superdesk-api';
import {assertNever} from './helpers/typescript-helpers';
import {isObject, omit} from 'lodash';
import moment from 'moment';

export const DEFAULT_ENGLISH_TRANSLATIONS = {'': {'language': 'en', 'plural-forms': 'nplurals=2; plural=(n != 1);'}};
const language = getUserInterfaceLanguage();
Expand Down Expand Up @@ -364,7 +365,14 @@ export function toQueryString(
* Output example: "1970-01-19T22:57:38"
*/
export function toServerDateFormat(date: Date): string {
return date.toJSON().slice(0, 19);
return moment(date).toISOString(true).slice(0, 19);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need moment here? Could you implement the same thing without it? We're creating a black box here by using moment that supports a thousand features and it's not clear which will be invoked here. You could also use a function from date-fns - those are much more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need something that won't change the time when converting it to ISO format, will check date-fns

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like formatISO from date-fns does the job. It'd be good to add a comment also that this is your intention so someone who looks at it in the future understands why aren't you using the built-in ".toISOString"

}

/**
* Parse server date without timezone so it won't convert it to local timezone.
*/
export function fromServerDateFormat(date: string): Date {
return new Date(date.slice(0, 19));
}

export function getItemLabel(item: IArticle): string {
Expand Down
Loading