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 all commits
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:

- run: npm ci
- run: npm run test
env:
TZ: "Europe/Prague"

e2e:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var path = require('path');
var grunt = require('grunt');
var makeConfig = require('./webpack.config.js');

process.env.TZ = "Europe/Prague";

module.exports = function(config) {
var webpackConfig = makeConfig(grunt);

Expand Down
281 changes: 208 additions & 73 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"classnames": "2.2.5",
"css-loader": "0.28.10",
"d3": "3.5.17",
"date-fns": "^2.7.0",
"date-fns": "^2.16.0",
"diff-match-patch": "1.0.0",
"docs-soap": "github:tomaskikutis/docs-soap#convert-tables",
"draft-js": "github:superdesk/draft-js#master",
Expand Down Expand Up @@ -122,7 +122,7 @@
"sass-loader": "6.0.6",
"shortid": "2.2.8",
"style-loader": "0.20.2",
"superdesk-ui-framework": "^3.0.62",
"superdesk-ui-framework": "^3.0.63",
"ts-loader": "3.5.0",
"tslint": "5.11.0",
"typescript": "4.9.5",
Expand All @@ -134,7 +134,7 @@
"devDependencies": {
"@superdesk/build-tools": "file:build-tools",
"@types/classnames": "^2.2.10",
"@types/webpack-env": "^1.18.1",
"@types/webpack-env": "^1.18.3",
"@types/webrtc": "0.0.33",
"enzyme": "3.9.0",
"enzyme-adapter-react-16": "^1.15.5",
Expand Down
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
12 changes: 12 additions & 0 deletions scripts/core/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {toServerDateFormat} from './utils';

describe('utils', () => {
describe('toServerDateFormat', () => {
it('can convert to server format without switching to UTC', () => {
const d = new Date('2023-11-06T16:00:00');

expect(d.toISOString()).toEqual('2023-11-06T15:00:00.000Z');
expect(toServerDateFormat(d)).toEqual('2023-11-06T16:00:00');
});
});
});
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 formatISO from 'date-fns/formatISO';

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 formatISO(date).slice(0, 19);
}

/**
* 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