@deriv-com/smartcharts-champion 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -10
- package/app/ChartHistory.tsx +5 -5
- package/app/DateTimePicker/Calendar.tsx +37 -36
- package/app/DateTimePicker/DatePicker.tsx +8 -8
- package/app/DateTimePicker/TimePicker.tsx +17 -16
- package/app/DateTimePicker/calendar.props.ts +4 -1
- package/app/DateTimePicker/panels/CalendarDays.tsx +15 -16
- package/app/DateTimePicker/panels/calendar_decades.tsx +3 -3
- package/app/DateTimePicker/panels/calendar_months.tsx +4 -4
- package/app/DateTimePicker/panels/calendar_years.tsx +3 -3
- package/app/index.tsx +3 -3
- package/dist/chart/canvaskit/canvaskit.js +1 -1
- package/dist/chart/canvaskit/chromium/canvaskit.js +1 -1
- package/dist/chart/canvaskit/skwasm.js +1 -1
- package/dist/chart/flutter.js +1 -1
- package/dist/chart/flutter_bootstrap.js +1 -1
- package/dist/chart/flutter_service_worker.js +1 -1
- package/dist/chart/main.dart.js +1 -1
- package/dist/flutter-chart-adapter-102ca2.smartcharts.js +2 -0
- package/dist/flutter-chart-adapter-102ca2.smartcharts.js.map +1 -0
- package/dist/html2canvas-06703d.smartcharts.js +2 -0
- package/dist/html2canvas-06703d.smartcharts.js.map +1 -0
- package/dist/resize-observer-polyfill-55e30f.smartcharts.js +2 -0
- package/dist/resize-observer-polyfill-55e30f.smartcharts.js.map +1 -0
- package/dist/smartcharts.css +17 -298
- package/dist/smartcharts.css.map +1 -1
- package/dist/smartcharts.js +1 -2
- package/dist/smartcharts.js.map +1 -1
- package/package.json +5 -3
- package/dist/flutter-chart-adapter-68a4b9.smartcharts.js +0 -2
- package/dist/flutter-chart-adapter-68a4b9.smartcharts.js.map +0 -1
- package/dist/html2canvas-cffc8d.smartcharts.js +0 -3
- package/dist/html2canvas-cffc8d.smartcharts.js.LICENSE.txt +0 -18
- package/dist/html2canvas-cffc8d.smartcharts.js.map +0 -1
- package/dist/resize-observer-polyfill-75583b.smartcharts.js +0 -2
- package/dist/resize-observer-polyfill-75583b.smartcharts.js.map +0 -1
- package/dist/smartcharts.js.LICENSE.txt +0 -25
- /package/dist/{ar-json-132882.smartcharts.js → ar-json-0f73c7.smartcharts.js} +0 -0
- /package/dist/{bn-json-3c3817.smartcharts.js → bn-json-0d6eca.smartcharts.js} +0 -0
- /package/dist/{de-json-cd6db1.smartcharts.js → de-json-b3239f.smartcharts.js} +0 -0
- /package/dist/{es-json-fe3c16.smartcharts.js → es-json-85869d.smartcharts.js} +0 -0
- /package/dist/{fr-json-160680.smartcharts.js → fr-json-69f949.smartcharts.js} +0 -0
- /package/dist/{id-json-93be22.smartcharts.js → id-json-fd1066.smartcharts.js} +0 -0
- /package/dist/{it-json-b97c0e.smartcharts.js → it-json-3a6a0a.smartcharts.js} +0 -0
- /package/dist/{km-json-b18af3.smartcharts.js → km-json-6c33fb.smartcharts.js} +0 -0
- /package/dist/{ko-json-ae350f.smartcharts.js → ko-json-6618e5.smartcharts.js} +0 -0
- /package/dist/{messages-json-071dd8.smartcharts.js → messages-json-dcf345.smartcharts.js} +0 -0
- /package/dist/{mn-json-462fe2.smartcharts.js → mn-json-324f5d.smartcharts.js} +0 -0
- /package/dist/{nl-json-cb7af5.smartcharts.js → nl-json-0b1291.smartcharts.js} +0 -0
- /package/dist/{pl-json-a13690.smartcharts.js → pl-json-408399.smartcharts.js} +0 -0
- /package/dist/{pt-json-f8cb2c.smartcharts.js → pt-json-f62ac5.smartcharts.js} +0 -0
- /package/dist/{ru-json-87f74a.smartcharts.js → ru-json-64ef7d.smartcharts.js} +0 -0
- /package/dist/{si-json-4aadfc.smartcharts.js → si-json-da53eb.smartcharts.js} +0 -0
- /package/dist/{sw-json-5f53b9.smartcharts.js → sw-json-637b1d.smartcharts.js} +0 -0
- /package/dist/{th-json-8fdb2d.smartcharts.js → th-json-0a9ace.smartcharts.js} +0 -0
- /package/dist/{tr-json-7e2a6c.smartcharts.js → tr-json-9b9028.smartcharts.js} +0 -0
- /package/dist/{uz-json-d1249b.smartcharts.js → uz-json-bed401.smartcharts.js} +0 -0
- /package/dist/{vi-json-505a69.smartcharts.js → vi-json-86cd8b.smartcharts.js} +0 -0
- /package/dist/{zh-json-b03f3e.smartcharts.js → zh-json-bf1035.smartcharts.js} +0 -0
- /package/dist/{zh_cn-json-2a3926.smartcharts.js → zh_cn-json-06d50e.smartcharts.js} +0 -0
- /package/dist/{zh_tw-json-72e8e0.smartcharts.js → zh_tw-json-891074.smartcharts.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
# [1.
|
|
1
|
+
# [1.5.0](https://github.com/deriv-com/smartcharts-champion/compare/v1.4.1...v1.5.0) (2026-01-12)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### ✨ Features
|
|
5
5
|
|
|
6
|
-
*
|
|
7
|
-
* new transaltions ([5d6edc0](https://github.com/deriv-com/smartcharts-champion/commit/5d6edc02b301f02866b7e6b125d5631942a203c0))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### 🐛 Bug Fixes
|
|
11
|
-
|
|
12
|
-
* added description to the download section ([e3459d3](https://github.com/deriv-com/smartcharts-champion/commit/e3459d372bbe497be8ab09d9d03ef3baba10f7ff))
|
|
13
|
-
* added description to the download section ([98ed3b7](https://github.com/deriv-com/smartcharts-champion/commit/98ed3b7d2f7277e401dec59be6ea11ead50c33b7))
|
|
14
|
-
* fix the translation for zh_tw ([d1c97c6](https://github.com/deriv-com/smartcharts-champion/commit/d1c97c637bbb7e3fb7ce79f0677d20ae90c6a6c1))
|
|
6
|
+
* replace legacy moment with dayJs ([#162](https://github.com/deriv-com/smartcharts-champion/issues/162)) ([e7d2e17](https://github.com/deriv-com/smartcharts-champion/commit/e7d2e17d8cc72aed072bd2d846fc893f3f4001db))
|
package/app/ChartHistory.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import dayjs from '../src/utils/dayjs-config';
|
|
3
3
|
import DatePicker from './DateTimePicker/DatePicker';
|
|
4
4
|
import TimePicker from './DateTimePicker/TimePicker';
|
|
5
5
|
import './chart-history.scss';
|
|
@@ -9,7 +9,7 @@ type TChartHistoryProps = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const ChartHistory = React.memo(({ onChange }: TChartHistoryProps) => {
|
|
12
|
-
const [date, setDate] = React.useState(
|
|
12
|
+
const [date, setDate] = React.useState(dayjs().format('YYYY/MM/DD'));
|
|
13
13
|
const [focusOnDate, setFocusOnDate] = React.useState(false);
|
|
14
14
|
const [focusOnTime, setFocusOnTime] = React.useState(false);
|
|
15
15
|
const [time, setTime] = React.useState('00:00');
|
|
@@ -56,8 +56,8 @@ const ChartHistory = React.memo(({ onChange }: TChartHistoryProps) => {
|
|
|
56
56
|
has_today_btn
|
|
57
57
|
value={date}
|
|
58
58
|
onChange={onChangeDate}
|
|
59
|
-
min_date={
|
|
60
|
-
max_date={
|
|
59
|
+
min_date={dayjs.utc().subtract(1, 'years').toDate().toString()}
|
|
60
|
+
max_date={dayjs.utc().toDate().toString()}
|
|
61
61
|
display_format='DD MMM YYYY'
|
|
62
62
|
/>
|
|
63
63
|
<TimePicker
|
|
@@ -65,7 +65,7 @@ const ChartHistory = React.memo(({ onChange }: TChartHistoryProps) => {
|
|
|
65
65
|
name='time'
|
|
66
66
|
focus={focusOnTime}
|
|
67
67
|
disableFocus={onDisableFocus}
|
|
68
|
-
start_date={
|
|
68
|
+
start_date={dayjs(date, 'YYYY/MM/DD').valueOf() / 1000}
|
|
69
69
|
value={time}
|
|
70
70
|
onChange={onChangeTime}
|
|
71
71
|
/>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import dayjs from '../../src/utils/dayjs-config';
|
|
3
4
|
import { Wrapper } from '../../src/components/Icons';
|
|
4
5
|
import CalendarICInfo from '../icons/ic-calendar-info.svg';
|
|
5
6
|
import { CalendarDays, CalendarMonths, CalendarYears, CalendarDecades } from './panels/index';
|
|
@@ -52,7 +53,7 @@ type TCalendarPanelProps = {
|
|
|
52
53
|
min_date: string;
|
|
53
54
|
start_date?: number;
|
|
54
55
|
calendar_date: string;
|
|
55
|
-
isPeriodDisabled: (date:
|
|
56
|
+
isPeriodDisabled: (date: Dayjs | string, unit: dayjs.OpUnitType) => boolean;
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
type TCalendarHeaderProps = {
|
|
@@ -79,14 +80,14 @@ type TCalendarHeaderProps = {
|
|
|
79
80
|
|
|
80
81
|
const CalendarButton = ({ children, className, is_hidden, label, onClick }: TCalendarButtonProps) => {
|
|
81
82
|
return (
|
|
82
|
-
|
|
83
|
+
<>
|
|
83
84
|
{!is_hidden && (
|
|
84
85
|
<span className={className} onClick={onClick}>
|
|
85
86
|
{label}
|
|
86
87
|
{children}
|
|
87
88
|
</span>
|
|
88
89
|
)}
|
|
89
|
-
|
|
90
|
+
</>
|
|
90
91
|
);
|
|
91
92
|
};
|
|
92
93
|
|
|
@@ -125,7 +126,7 @@ const CalendarHeader = ({
|
|
|
125
126
|
const is_month_view = calendar_view === 'month';
|
|
126
127
|
const is_year_view = calendar_view === 'year';
|
|
127
128
|
const is_decade_view = calendar_view === 'decade';
|
|
128
|
-
const moment_date =
|
|
129
|
+
const moment_date = dayjs.utc(calendar_date);
|
|
129
130
|
const onPreviousYearClick = () => {
|
|
130
131
|
if (is_date_view || is_month_view) onClick.previousYear();
|
|
131
132
|
|
|
@@ -152,13 +153,13 @@ const CalendarHeader = ({
|
|
|
152
153
|
<div className='calendar-header'>
|
|
153
154
|
<CalendarButton
|
|
154
155
|
className={`calendar-prev-year-btn ${
|
|
155
|
-
isPeriodDisabled(moment_date.
|
|
156
|
+
isPeriodDisabled(moment_date.subtract(1, 'month'), 'month') ? 'hidden' : ''
|
|
156
157
|
}`}
|
|
157
158
|
onClick={onPreviousYearClick}
|
|
158
159
|
/>
|
|
159
160
|
<CalendarButton
|
|
160
161
|
className={`calendar-prev-month-btn ${
|
|
161
|
-
isPeriodDisabled(moment_date.
|
|
162
|
+
isPeriodDisabled(moment_date.subtract(1, 'month'), 'month') ? 'hidden' : ''
|
|
162
163
|
}`}
|
|
163
164
|
is_hidden={!is_date_view}
|
|
164
165
|
onClick={onClick.previousMonth}
|
|
@@ -176,28 +177,22 @@ const CalendarHeader = ({
|
|
|
176
177
|
<CalendarButton className='calendar-select-year-btn' onClick={onSelectYearClick}>
|
|
177
178
|
{(is_date_view || is_month_view) && moment_date.year()}
|
|
178
179
|
{is_year_view &&
|
|
179
|
-
`${moment_date.
|
|
180
|
-
.clone()
|
|
181
|
-
.add(10, 'years')
|
|
182
|
-
.year()}`}
|
|
180
|
+
`${moment_date.subtract(1, 'years').year()}-${moment_date.add(10, 'years').year()}`}
|
|
183
181
|
{is_decade_view &&
|
|
184
|
-
`${moment_date.
|
|
185
|
-
.clone()
|
|
186
|
-
.add(109, 'years')
|
|
187
|
-
.year()}`}
|
|
182
|
+
`${moment_date.subtract(10, 'years').year()}-${moment_date.add(109, 'years').year()}`}
|
|
188
183
|
</CalendarButton>
|
|
189
184
|
</div>
|
|
190
185
|
|
|
191
186
|
<CalendarButton
|
|
192
187
|
className={`calendar-next-month-btn ${
|
|
193
|
-
isPeriodDisabled(moment_date.
|
|
188
|
+
isPeriodDisabled(moment_date.add(1, 'month'), 'month') ? 'hidden' : ''
|
|
194
189
|
}`}
|
|
195
190
|
is_hidden={!is_date_view}
|
|
196
191
|
onClick={onClick.nextMonth}
|
|
197
192
|
/>
|
|
198
193
|
<CalendarButton
|
|
199
194
|
className={`calendar-next-year-btn ${
|
|
200
|
-
isPeriodDisabled(moment_date.
|
|
195
|
+
isPeriodDisabled(moment_date.add(1, 'month'), 'month') ? 'hidden' : ''
|
|
201
196
|
}`}
|
|
202
197
|
onClick={onNextYearClick}
|
|
203
198
|
/>
|
|
@@ -214,13 +209,13 @@ const Calendar = React.forwardRef<TCalendarRefProps, TCalendarProps>(
|
|
|
214
209
|
id,
|
|
215
210
|
date_format = 'YYYY-MM-DD',
|
|
216
211
|
start_date,
|
|
217
|
-
max_date =
|
|
218
|
-
min_date =
|
|
212
|
+
max_date = dayjs().utc().add(120, 'y').format('YYYY-MM-DD'), // by default, max_date is set to 120 years after today
|
|
213
|
+
min_date = dayjs(0).utc().format('YYYY-MM-DD'), // by default, min_date is set to Unix Epoch (January 1st 1970)
|
|
219
214
|
onSelect,
|
|
220
215
|
}: TCalendarProps,
|
|
221
216
|
ref
|
|
222
217
|
) => {
|
|
223
|
-
const [calendar_date, setCalendarDate] = React.useState(
|
|
218
|
+
const [calendar_date, setCalendarDate] = React.useState(dayjs.utc(start_date).format(date_format));
|
|
224
219
|
const [selected_date, setSelectedDate] = React.useState('');
|
|
225
220
|
const [calendar_view, setCalendarView] = React.useState('date');
|
|
226
221
|
|
|
@@ -289,19 +284,19 @@ const Calendar = React.forwardRef<TCalendarRefProps, TCalendarProps>(
|
|
|
289
284
|
},
|
|
290
285
|
};
|
|
291
286
|
|
|
292
|
-
const navigateTo = (value: number, unit:
|
|
293
|
-
let new_date =
|
|
287
|
+
const navigateTo = (value: number, unit: dayjs.ManipulateType, is_add: boolean) => {
|
|
288
|
+
let new_date = dayjs
|
|
294
289
|
.utc(calendar_date, date_format)
|
|
295
290
|
[is_add ? 'add' : 'subtract'](value, unit)
|
|
296
291
|
.format(date_format);
|
|
297
292
|
|
|
298
293
|
if (unit === 'months' && isPeriodDisabled(new_date, 'month')) return;
|
|
299
294
|
|
|
300
|
-
if (unit === 'years' && isPeriodDisabled(new_date, '
|
|
295
|
+
if (unit === 'years' && isPeriodDisabled(new_date, 'year')) {
|
|
301
296
|
new_date = is_add ? max_date : min_date;
|
|
302
297
|
}
|
|
303
298
|
|
|
304
|
-
setCalendarDate(
|
|
299
|
+
setCalendarDate(dayjs.utc(new_date, date_format).format(date_format)); // formatted date
|
|
305
300
|
};
|
|
306
301
|
|
|
307
302
|
const updateSelectedDate = (e: React.SyntheticEvent<HTMLElement>, is_disabled: boolean) => {
|
|
@@ -313,9 +308,9 @@ const Calendar = React.forwardRef<TCalendarRefProps, TCalendarProps>(
|
|
|
313
308
|
return;
|
|
314
309
|
}
|
|
315
310
|
|
|
316
|
-
const moment_date =
|
|
317
|
-
const is_before = moment_date.isBefore(
|
|
318
|
-
const is_after = moment_date.isAfter(
|
|
311
|
+
const moment_date = dayjs.utc(e.target.dataset.date).startOf('day');
|
|
312
|
+
const is_before = moment_date.isBefore(dayjs.utc(min_date));
|
|
313
|
+
const is_after = moment_date.isAfter(dayjs.utc(max_date));
|
|
319
314
|
|
|
320
315
|
if (is_before || is_after) {
|
|
321
316
|
return;
|
|
@@ -344,20 +339,26 @@ const Calendar = React.forwardRef<TCalendarRefProps, TCalendarProps>(
|
|
|
344
339
|
|
|
345
340
|
const text = e.target.dataset?.[type]?.split('-')[0] || '';
|
|
346
341
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
342
|
+
let moment_date = dayjs.utc(calendar_date, date_format);
|
|
343
|
+
|
|
344
|
+
if (type === 'decade') {
|
|
345
|
+
moment_date = moment_date.year(Number(text));
|
|
346
|
+
} else if (type === 'year') {
|
|
347
|
+
moment_date = moment_date.year(Number(text));
|
|
348
|
+
} else if (type === 'month') {
|
|
349
|
+
moment_date = moment_date.month(Number(text));
|
|
350
|
+
}
|
|
350
351
|
|
|
351
352
|
const date = moment_date.format(date_format);
|
|
352
353
|
|
|
353
|
-
if (isPeriodDisabled(date, type === 'decade' ?
|
|
354
|
+
if (isPeriodDisabled(date, type === 'decade' ? 'year' : type)) return;
|
|
354
355
|
|
|
355
356
|
setCalendarDate(date);
|
|
356
357
|
setCalendarView(view_map[type as keyof typeof view_map]);
|
|
357
358
|
};
|
|
358
359
|
|
|
359
360
|
const setToday = () => {
|
|
360
|
-
const now =
|
|
361
|
+
const now = dayjs().utc().format(date_format);
|
|
361
362
|
|
|
362
363
|
setCalendarDate(now);
|
|
363
364
|
setSelectedDate(now);
|
|
@@ -368,10 +369,10 @@ const Calendar = React.forwardRef<TCalendarRefProps, TCalendarProps>(
|
|
|
368
369
|
}
|
|
369
370
|
};
|
|
370
371
|
|
|
371
|
-
const isPeriodDisabled = (date:
|
|
372
|
-
const start_of_period =
|
|
373
|
-
const end_of_period =
|
|
374
|
-
return end_of_period.isBefore(
|
|
372
|
+
const isPeriodDisabled = (date: Dayjs | string, unit: dayjs.OpUnitType) => {
|
|
373
|
+
const start_of_period = dayjs.utc(date).startOf(unit);
|
|
374
|
+
const end_of_period = dayjs.utc(date).endOf(unit);
|
|
375
|
+
return end_of_period.isBefore(dayjs.utc(min_date)) || start_of_period.isAfter(dayjs.utc(max_date));
|
|
375
376
|
};
|
|
376
377
|
|
|
377
378
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import dayjs from '../../src/utils/dayjs-config';
|
|
3
3
|
import Calendar, { TCalendarRefProps } from './Calendar';
|
|
4
4
|
import './date-picker.scss';
|
|
5
5
|
import { Wrapper } from '../../src/components/Icons';
|
|
@@ -53,7 +53,7 @@ const DatePickerInput = ({
|
|
|
53
53
|
mode,
|
|
54
54
|
display_format,
|
|
55
55
|
}: TDatePickerInputProps) => {
|
|
56
|
-
const input_value = format ?
|
|
56
|
+
const input_value = format ? dayjs(value, 'YYYY-MM-DD').format(display_format) : value;
|
|
57
57
|
return (
|
|
58
58
|
<input
|
|
59
59
|
id={id}
|
|
@@ -68,14 +68,14 @@ const DatePickerInput = ({
|
|
|
68
68
|
);
|
|
69
69
|
};
|
|
70
70
|
const formatDate = (date: string, date_format = 'YYYY-MM-DD') =>
|
|
71
|
-
|
|
71
|
+
dayjs(date || undefined, date_format).format(date_format);
|
|
72
72
|
/**
|
|
73
73
|
* return the number of days from today to date specified
|
|
74
74
|
* @param {String} date the date to calculate number of days from today
|
|
75
75
|
* @return {Number} an integer of the number of days
|
|
76
76
|
*/
|
|
77
77
|
const daysFromTodayTo = (date: string): string => {
|
|
78
|
-
const diff =
|
|
78
|
+
const diff = dayjs(date).utc().diff(dayjs().utc(), 'days');
|
|
79
79
|
return !date || diff < 0 ? '' : (diff + 1).toString();
|
|
80
80
|
};
|
|
81
81
|
const DatePicker = React.memo((props: TDatePickerProps) => {
|
|
@@ -128,7 +128,7 @@ const DatePicker = React.memo((props: TDatePickerProps) => {
|
|
|
128
128
|
};
|
|
129
129
|
const onSelectCalendar = (selected_date: string, _is_datepicker_visible = false) => {
|
|
130
130
|
let _selected_date = selected_date;
|
|
131
|
-
if (!
|
|
131
|
+
if (!dayjs.utc(_selected_date).isValid()) {
|
|
132
132
|
_selected_date = '';
|
|
133
133
|
}
|
|
134
134
|
if (mode === 'duration') {
|
|
@@ -142,10 +142,10 @@ const DatePicker = React.memo((props: TDatePickerProps) => {
|
|
|
142
142
|
const updateDatePickerValue = (_value: string, _mode?: string) => {
|
|
143
143
|
setValue(_value, updateStore);
|
|
144
144
|
// update Calendar
|
|
145
|
-
const new_date = _mode === 'duration' ?
|
|
146
|
-
if (calendarRef.current && (
|
|
145
|
+
const new_date = _mode === 'duration' ? dayjs.utc().add(Number(_value), 'days').format(date_format) : _value;
|
|
146
|
+
if (calendarRef.current && (dayjs.utc(new_date, date_format).isValid() || !new_date)) {
|
|
147
147
|
if (!new_date) {
|
|
148
|
-
const current_date =
|
|
148
|
+
const current_date = dayjs.utc(start_date).format(date_format);
|
|
149
149
|
calendarRef.current.setCalendarDate(current_date);
|
|
150
150
|
calendarRef.current.setSelectedDate(current_date);
|
|
151
151
|
} else {
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
/* eslint-disable react/no-did-update-set-state */
|
|
4
4
|
/* eslint-disable react/no-unused-state */
|
|
5
5
|
import { observer } from 'mobx-react-lite';
|
|
6
|
-
import
|
|
6
|
+
import { Dayjs } from 'dayjs';
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import dayjs from '../../src/utils/dayjs-config';
|
|
8
9
|
import './time-picker.scss';
|
|
9
10
|
import { Wrapper } from '../../src/components/Icons';
|
|
10
11
|
import Time from '../icons/ic-time.svg';
|
|
@@ -34,13 +35,13 @@ type TTimerPickerProps = {
|
|
|
34
35
|
|
|
35
36
|
const TimeIcon = Wrapper(Time);
|
|
36
37
|
const isSessionAvailable = (
|
|
37
|
-
compare_moment =
|
|
38
|
-
end_moment =
|
|
38
|
+
compare_moment = dayjs().utc(),
|
|
39
|
+
end_moment = dayjs().utc(),
|
|
39
40
|
should_only_check_hour = false
|
|
40
41
|
) => {
|
|
41
42
|
const offset = new Date().getTimezoneOffset() * 60 * 1000;
|
|
42
|
-
const end_compare = should_only_check_hour ? end_moment.
|
|
43
|
-
const start_compare = end_compare.
|
|
43
|
+
const end_compare = should_only_check_hour ? end_moment.minute(0).second(0) : end_moment;
|
|
44
|
+
const start_compare = end_compare.subtract(1, 'year');
|
|
44
45
|
const end_time = end_compare.valueOf() + offset;
|
|
45
46
|
const start_time = start_compare.valueOf() + offset;
|
|
46
47
|
return end_time - compare_moment.valueOf() > 0 && compare_moment.valueOf() - start_time > 0;
|
|
@@ -69,8 +70,8 @@ const TimePickerDropdown = React.memo(
|
|
|
69
70
|
const selectOption = (type: string, new_value: string, is_enabled = true) => {
|
|
70
71
|
if (is_enabled) {
|
|
71
72
|
const [prev_hour, prev_minute] = (value || '00:00').split(':');
|
|
72
|
-
const start_moment =
|
|
73
|
-
const start_moment_clone = start_moment.
|
|
73
|
+
const start_moment = dayjs(start_date * 1000 || undefined);
|
|
74
|
+
const start_moment_clone = start_moment.minute(0).second(0);
|
|
74
75
|
if ((type === 'h' && new_value !== prev_hour) || (type === 'm' && new_value !== prev_minute)) {
|
|
75
76
|
setLastUpdatedType(type);
|
|
76
77
|
type === 'h' ? setIsHourSelected(true) : setIsMinuteSelected(true);
|
|
@@ -103,9 +104,9 @@ const TimePickerDropdown = React.memo(
|
|
|
103
104
|
setIsHourSelected(false);
|
|
104
105
|
setIsMinuteSelected(false);
|
|
105
106
|
};
|
|
106
|
-
const start_moment =
|
|
107
|
-
const start_moment_clone = start_moment.
|
|
108
|
-
const end_moment =
|
|
107
|
+
const start_moment = dayjs(start_date * 1000 || undefined);
|
|
108
|
+
const start_moment_clone = start_moment.minute(0).second(0);
|
|
109
|
+
const end_moment = dayjs().utc();
|
|
109
110
|
let [hour, minute] = ['00', '00'];
|
|
110
111
|
if (value.match(/^([0-9]|[0-1][0-9]|2[0-3]):([0-9]|[0-5][0-9])(:([0-9]|[0-5][0-9]))?$/)) {
|
|
111
112
|
[hour, minute] = value.split(':');
|
|
@@ -210,9 +211,9 @@ const TimePicker = (props: TTimerPickerProps) => {
|
|
|
210
211
|
[name, onChange, props.value]
|
|
211
212
|
);
|
|
212
213
|
React.useEffect(() => {
|
|
213
|
-
const findAvailabeTime = (start_moment_clone:
|
|
214
|
+
const findAvailabeTime = (start_moment_clone: Dayjs) => {
|
|
214
215
|
let last_available_min, desire_time;
|
|
215
|
-
const hour =
|
|
216
|
+
const hour = dayjs().utc().format('HH');
|
|
216
217
|
minutes.forEach(min => {
|
|
217
218
|
desire_time = start_moment_clone.hour(+hour).minute(+min);
|
|
218
219
|
if (isSessionAvailable(desire_time)) {
|
|
@@ -227,8 +228,8 @@ const TimePicker = (props: TTimerPickerProps) => {
|
|
|
227
228
|
}
|
|
228
229
|
if (focus) {
|
|
229
230
|
const [prev_hour, prev_minute] = (prev_value || '00:00').split(':');
|
|
230
|
-
const start_moment =
|
|
231
|
-
const start_moment_clone = start_moment.
|
|
231
|
+
const start_moment = dayjs(start_date * 1000 || undefined);
|
|
232
|
+
const start_moment_clone = start_moment.minute(0).second(0);
|
|
232
233
|
const desire_time = start_moment_clone.hour(parseInt(prev_hour)).minute(parseInt(prev_minute));
|
|
233
234
|
if (!isSessionAvailable(desire_time)) {
|
|
234
235
|
findAvailabeTime(start_moment_clone);
|
|
@@ -241,7 +242,7 @@ const TimePicker = (props: TTimerPickerProps) => {
|
|
|
241
242
|
{is_nativepicker ? (
|
|
242
243
|
<input type='time' id={`${prefix_class}-input`} value={value} onChange={handleChange} name={name} />
|
|
243
244
|
) : (
|
|
244
|
-
|
|
245
|
+
<>
|
|
245
246
|
<span className='time-picker-container' onClick={toggleDropDown}>
|
|
246
247
|
<input
|
|
247
248
|
type='text'
|
|
@@ -262,7 +263,7 @@ const TimePicker = (props: TTimerPickerProps) => {
|
|
|
262
263
|
start_date={start_date}
|
|
263
264
|
value={value}
|
|
264
265
|
/>
|
|
265
|
-
|
|
266
|
+
</>
|
|
266
267
|
)}
|
|
267
268
|
</div>
|
|
268
269
|
);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { Dayjs } from 'dayjs';
|
|
2
|
+
import dayjs from '../../src/utils/dayjs-config';
|
|
3
|
+
|
|
1
4
|
export type TCalendarViewProps = {
|
|
2
5
|
calendar_date: string;
|
|
3
|
-
isPeriodDisabled: (date:
|
|
6
|
+
isPeriodDisabled: (date: Dayjs | string, unit: dayjs.OpUnitType) => boolean;
|
|
4
7
|
selected_date: string;
|
|
5
8
|
onClick: {
|
|
6
9
|
date: (e: React.SyntheticEvent<HTMLElement>, is_disabled: boolean) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/no-array-index-key */
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import moment from 'moment';
|
|
4
3
|
import React from 'react';
|
|
4
|
+
import dayjs from '../../../src/utils/dayjs-config';
|
|
5
5
|
|
|
6
6
|
type TCalendarProps = {
|
|
7
7
|
date_format: string;
|
|
@@ -37,33 +37,33 @@ const getDays = ({
|
|
|
37
37
|
}: TCalendarProps) => {
|
|
38
38
|
const dates = [];
|
|
39
39
|
const days: React.ReactElement[] = [];
|
|
40
|
-
const moment_today =
|
|
41
|
-
const moment_cur_date =
|
|
40
|
+
const moment_today = dayjs().utc().startOf('day');
|
|
41
|
+
const moment_cur_date = dayjs.utc(calendar_date);
|
|
42
42
|
const num_of_days = moment_cur_date.daysInMonth() + 1;
|
|
43
|
-
const moment_month_start = moment_cur_date.
|
|
44
|
-
const moment_month_end = moment_cur_date.
|
|
45
|
-
const first_day = calcDayIndexFromMonday(moment_month_start.day()); //
|
|
43
|
+
const moment_month_start = moment_cur_date.startOf('month');
|
|
44
|
+
const moment_month_end = moment_cur_date.endOf('month');
|
|
45
|
+
const first_day = calcDayIndexFromMonday(moment_month_start.day()); // dayjs method '.day()' return index the day of the week, with Sunday as 0 and Saturday as 6.
|
|
46
46
|
const last_day = calcDayIndexFromMonday(moment_month_end.day());
|
|
47
|
-
const moment_min_date =
|
|
48
|
-
const moment_max_date =
|
|
49
|
-
const moment_selected =
|
|
47
|
+
const moment_min_date = dayjs.utc(min_date);
|
|
48
|
+
const moment_max_date = dayjs.utc(max_date);
|
|
49
|
+
const moment_selected = dayjs.utc(selected_date);
|
|
50
50
|
|
|
51
51
|
for (let i = first_day; i > 0; i--) {
|
|
52
|
-
dates.push(moment_month_start.
|
|
52
|
+
dates.push(moment_month_start.subtract(i, 'day').format(date_format));
|
|
53
53
|
}
|
|
54
54
|
for (let idx = 1; idx < num_of_days; idx += 1) {
|
|
55
|
-
dates.push(moment_cur_date.
|
|
55
|
+
dates.push(moment_cur_date.format(date_format.replace('DD', padLeft(idx, 2, '0'))));
|
|
56
56
|
}
|
|
57
57
|
for (let i = 1; i <= 6 - last_day; i++) {
|
|
58
|
-
dates.push(moment_month_end.
|
|
58
|
+
dates.push(moment_month_end.add(i, 'day').format(date_format));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const moment_start_date =
|
|
61
|
+
const moment_start_date = dayjs
|
|
62
62
|
.unix(start_date || 0)
|
|
63
63
|
.utc()
|
|
64
64
|
.startOf('day');
|
|
65
65
|
dates.map(date => {
|
|
66
|
-
const moment_date =
|
|
66
|
+
const moment_date = dayjs.utc(date).startOf('day');
|
|
67
67
|
const is_active = selected_date && moment_date.isSame(moment_selected);
|
|
68
68
|
const is_today = moment_date.isSame(moment_today, 'day');
|
|
69
69
|
const is_disabled: boolean =
|
|
@@ -71,8 +71,7 @@ const getDays = ({
|
|
|
71
71
|
moment_date.isAfter(moment_max_date) ||
|
|
72
72
|
// for forward starting accounts, only show same day as start date and the day after
|
|
73
73
|
(start_date
|
|
74
|
-
? moment_date.isBefore(moment_start_date) ||
|
|
75
|
-
moment_date.isAfter(moment_start_date.clone().add(1, 'day'))
|
|
74
|
+
? moment_date.isBefore(moment_start_date) || moment_date.isAfter(moment_start_date.add(1, 'day'))
|
|
76
75
|
: false);
|
|
77
76
|
|
|
78
77
|
const is_other_month = moment_date.month() !== moment_cur_date.month();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable react/no-array-index-key */
|
|
2
|
-
import
|
|
2
|
+
import dayjs from '../../../src/utils/dayjs-config';
|
|
3
3
|
import { TCalendarViewProps } from '../calendar.props';
|
|
4
4
|
|
|
5
5
|
export const CalendarDecades = ({ calendar_date, isPeriodDisabled, onClick, selected_date }: TCalendarViewProps) => {
|
|
6
|
-
const selected_year =
|
|
7
|
-
const moment_date =
|
|
6
|
+
const selected_year = dayjs.utc(selected_date).year();
|
|
7
|
+
const moment_date = dayjs.utc(calendar_date);
|
|
8
8
|
|
|
9
9
|
const decades = [];
|
|
10
10
|
let min_year = moment_date.year() - 10;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable react/no-array-index-key */
|
|
2
|
-
import
|
|
2
|
+
import dayjs from '../../../src/utils/dayjs-config';
|
|
3
3
|
import { TCalendarViewProps } from '../calendar.props';
|
|
4
4
|
|
|
5
5
|
const getMonthHeaders = () => ({
|
|
@@ -18,8 +18,8 @@ const getMonthHeaders = () => ({
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const CalendarMonths = ({ calendar_date, isPeriodDisabled, onClick, selected_date }: TCalendarViewProps) => {
|
|
21
|
-
const moment_date =
|
|
22
|
-
const selected_month =
|
|
21
|
+
const moment_date = dayjs.utc(calendar_date);
|
|
22
|
+
const selected_month = dayjs.utc(selected_date).month();
|
|
23
23
|
const month_headers = getMonthHeaders();
|
|
24
24
|
|
|
25
25
|
return (
|
|
@@ -28,7 +28,7 @@ export const CalendarMonths = ({ calendar_date, isPeriodDisabled, onClick, selec
|
|
|
28
28
|
<span
|
|
29
29
|
key={month}
|
|
30
30
|
className={`calendar-month ${idx === selected_month ? 'active' : ''} ${
|
|
31
|
-
isPeriodDisabled(moment_date.month(
|
|
31
|
+
isPeriodDisabled(moment_date.month(idx), 'month') ? 'disabled' : ''
|
|
32
32
|
} `}
|
|
33
33
|
onClick={onClick.month}
|
|
34
34
|
data-month={idx}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable react/no-array-index-key */
|
|
2
|
-
import
|
|
2
|
+
import dayjs from '../../../src/utils/dayjs-config';
|
|
3
3
|
import { TCalendarViewProps } from '../calendar.props';
|
|
4
4
|
|
|
5
5
|
export const CalendarYears = ({ calendar_date, isPeriodDisabled, onClick, selected_date }: TCalendarViewProps) => {
|
|
6
|
-
const selected_year =
|
|
7
|
-
const moment_date =
|
|
6
|
+
const selected_year = dayjs.utc(selected_date).year();
|
|
7
|
+
const moment_date = dayjs.utc(calendar_date);
|
|
8
8
|
const current_year = moment_date.year();
|
|
9
9
|
const years = [];
|
|
10
10
|
for (let year = current_year - 1; year < current_year + 11; year++) {
|
package/app/index.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from '@deriv-com/smartcharts'; // eslint-disable-line import/no-unresolved
|
|
18
18
|
import whyDidYouRender from '@welldone-software/why-did-you-render';
|
|
19
19
|
import { configure } from 'mobx';
|
|
20
|
-
import
|
|
20
|
+
import dayjs from '../src/utils/dayjs-config';
|
|
21
21
|
import React from 'react';
|
|
22
22
|
import { createRoot } from 'react-dom/client';
|
|
23
23
|
import { TNotification } from 'src/store/Notifier';
|
|
@@ -77,7 +77,7 @@ const chartId = '1';
|
|
|
77
77
|
const appId = localStorage.getItem('config.app_id') || 12812;
|
|
78
78
|
const serverUrl = getServerUrl();
|
|
79
79
|
const language = new URLSearchParams(window.location.search).get('l') || getLanguageStorage();
|
|
80
|
-
const today =
|
|
80
|
+
const today = dayjs().format('YYYY/MM/DD 00:00');
|
|
81
81
|
const connectionManager = new ConnectionManager({
|
|
82
82
|
appId,
|
|
83
83
|
language,
|
|
@@ -503,7 +503,7 @@ const App = () => {
|
|
|
503
503
|
{endEpoch ? (
|
|
504
504
|
<Marker className='chart-marker-historical' markerRef={onMarkerRef}>
|
|
505
505
|
<span>
|
|
506
|
-
{
|
|
506
|
+
{dayjs(endEpoch * 1000)
|
|
507
507
|
.utc()
|
|
508
508
|
.format('DD MMMM YYYY - HH:mm')}
|
|
509
509
|
</span>
|