Skip to content

Commit dd77681

Browse files
committed
fix(RelativeRangeDatePicker): last period preset title
1 parent 808bf51 commit dd77681

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

src/components/RelativeRangeDatePicker/components/Presets/i18n/en.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
"From start of month": "From start of month",
2626
"From start of year": "From start of year",
2727
"Previous month": "Previous month",
28-
"Last {count} {unit}": "Last {{count}} {{unit}}",
29-
"m": ["minute", "minutes", "minutes"],
30-
"h": ["hour", "hours", "hours"],
31-
"d": ["day", "days", "days"],
32-
"w": ["week", "weeks", "weeks"],
33-
"M": ["month", "months", "months"],
34-
"y": ["year", "years", "years"],
28+
"Last second": "Last second",
29+
"Last minute": "Last minute",
30+
"Last {count} second": ["Last {{count}} second", "Last {{count}} seconds", "Last {{count}} seconds"],
31+
"Last {count} minute": ["Last {{count}} minute", "Last {{count}} minutes", "Last {{count}} minutes"],
32+
"Last {count} hour": ["Last {{count}} hour", "Last {{count}} hours", "Last {{count}} hours"],
33+
"Last {count} day": ["Last {{count}} day", "Last {{count}} days", "Last {{count}} days"],
34+
"Last {count} week": ["Last {{count}} week", "Last {{count}} weeks", "Last {{count}} weeks"],
35+
"Last {count} month": ["Last {{count}} month", "Last {{count}} months", "Last {{count}} months"],
36+
"Last {count} year": ["Last {{count}} year", "Last {{count}} years", "Last {{count}} years"],
3537
"Main": "Main",
3638
"Other": "Other",
3739
"Range": "Range",

src/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
"From start of month": "С начала месяца",
2626
"From start of year": "С начала года",
2727
"Previous month": "Предыдущий месяц",
28-
"Last {count} {unit}": "Last {{count}} {{unit}}",
29-
"m": ["minute", "minutes", "minutes"],
30-
"h": ["hour", "hours", "hours"],
31-
"d": ["day", "days", "days"],
32-
"w": ["week", "weeks", "weeks"],
33-
"M": ["month", "months", "months"],
34-
"y": ["year", "years", "years"],
28+
"Last second": "Последняя секунда",
29+
"Last minute": "Последняя минута",
30+
"Last {count} second": ["Последняя {{count}} секунда", "Последние {{count}} секунды", "Последние {{count}} секунд"],
31+
"Last {count} minute": ["Последняя {{count}} минута", "Последние {{count}} минуты", "Последние {{count}} минут"],
32+
"Last {count} hour": ["Последний {{count}} час", "Последние {{count}} часа", "Последние {{count}} часов"],
33+
"Last {count} day": ["Последний {{count}} день", "Последние {{count}} дня", "Последние {{count}} дней"],
34+
"Last {count} week": ["Последняя {{count}} неделя", "Последние {{count}} недели", "Последние {{count}} недель"],
35+
"Last {count} month": ["Последний {{count}} месяц", "Последние {{count}} месяца", "Последние {{count}} месяцев"],
36+
"Last {count} year": ["Последний {{count}} год", "Последние {{count}} года", "Последние {{count}} лет"],
3537
"Main": "Основные",
3638
"Other": "Другие",
3739
"Range": "Период",

src/components/RelativeRangeDatePicker/components/Presets/utils.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ import {
1010
import type {Preset} from './defaultPresets';
1111
import {i18n} from './i18n';
1212

13+
const lastRe = /^now-(\d+)([smhdwMy])$/;
14+
15+
const oneUnit = {
16+
s: 'Last second',
17+
m: 'Last minute',
18+
h: 'Last hour',
19+
d: 'Last day',
20+
w: 'Last week',
21+
M: 'Last month',
22+
y: 'Last year',
23+
} as const;
24+
25+
const countUnit = {
26+
s: 'Last {count} second',
27+
m: 'Last {count} minute',
28+
h: 'Last {count} hour',
29+
d: 'Last {count} day',
30+
w: 'Last {count} week',
31+
M: 'Last {count} month',
32+
y: 'Last {count} year',
33+
} as const;
34+
1335
export function getPresetTitle(start: string, end: string, presets: Preset[] = allPresets) {
1436
const startText = start.replace(/\s+/g, '');
1537
const endText = end.replace(/\s+/g, '');
@@ -21,23 +43,21 @@ export function getPresetTitle(start: string, end: string, presets: Preset[] = a
2143
}
2244

2345
if (end === 'now') {
24-
const match = /^now-(\d+)([m|h|d|w|M|y])$/.exec(start);
46+
const match = lastRe.exec(startText);
2547
if (match) {
2648
const [, count, unit] = match;
2749
if (isDateUnit(unit)) {
28-
return i18n('Last {count} {unit}', {
29-
count,
30-
unit: i18n(unit, {count: Number(count)}),
31-
});
50+
const template = Number(count) === 1 ? oneUnit[unit] : countUnit[unit];
51+
return i18n(template, {count});
3252
}
3353
}
3454
}
3555

3656
return startText + ' — ' + endText;
3757
}
3858

39-
function isDateUnit(value: string): value is 'm' | 'h' | 'd' | 'w' | 'M' | 'y' {
40-
return ['m', 'h', 'd', 'w', 'M', 'y'].includes(value);
59+
function isDateUnit(value: string): value is 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y' {
60+
return ['s', 'm', 'h', 'd', 'w', 'M', 'y'].includes(value);
4161
}
4262

4363
export function filterPresets(presets: Preset[], minValue?: DateTime) {

src/components/RelativeRangeDatePicker/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function getDefaultTitle({
6767
value.start?.type === 'relative' &&
6868
value.end?.type === 'relative'
6969
) {
70-
return `${getPresetTitle(value.start.value, value.end.value, presets)}${tz}`;
70+
return `${getPresetTitle(value.start.value, value.end.value, presets)}`;
7171
}
7272

7373
const delimiter = ' — ';

0 commit comments

Comments
 (0)