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

[fields] Clean the order of the tokens in the formatTokenMap of each adapter #8112

Merged
merged 1 commit into from
Mar 3, 2023
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
25 changes: 20 additions & 5 deletions packages/x-date-pickers/src/AdapterDateFns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ import getWeek from 'date-fns/getWeek';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';

const formatTokenMap: FieldFormatTokenMap = {
// Year
y: 'year',
yy: 'year',
yyy: 'year',
yyyy: 'year',

// Month
M: 'month',
MM: 'month',
MMMM: { sectionType: 'month', contentType: 'letter' },
MMM: { sectionType: 'month', contentType: 'letter' },
LLL: { sectionType: 'month', contentType: 'letter' },
LLLL: { sectionType: 'month', contentType: 'letter' },

// Day of the month
d: 'day',
dd: 'day',

// Day of the week
E: { sectionType: 'weekDay', contentType: 'letter' },
EE: { sectionType: 'weekDay', contentType: 'letter' },
EEE: { sectionType: 'weekDay', contentType: 'letter' },
Expand All @@ -37,17 +46,23 @@ const formatTokenMap: FieldFormatTokenMap = {
cccc: { sectionType: 'weekDay', contentType: 'letter' },
ccccc: { sectionType: 'weekDay', contentType: 'letter' },
cccccc: { sectionType: 'weekDay', contentType: 'letter' },
d: 'day',
dd: 'day',

// Meridiem
a: 'meridiem',
aa: 'meridiem',
aaa: 'meridiem',

// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',

// Minutes
mm: 'minutes',

// Seconds
ss: 'seconds',
a: 'meridiem',
aa: 'meridiem',
aaa: 'meridiem',
};

export class AdapterDateFns extends BaseAdapterDateFns implements MuiPickersAdapter<Date> {
Expand Down
19 changes: 16 additions & 3 deletions packages/x-date-pickers/src/AdapterDateFnsJalali/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,40 @@ import longFormatters from 'date-fns-jalali/_lib/format/longFormatters';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';

const formatTokenMap: FieldFormatTokenMap = {
// Year
y: 'year',
yy: 'year',
yyy: 'year',
yyyy: 'year',

// Month
M: 'month',
MM: 'month',
MMMM: { sectionType: 'month', contentType: 'letter' },
MMM: { sectionType: 'month', contentType: 'letter' },
LLL: { sectionType: 'month', contentType: 'letter' },
LLLL: { sectionType: 'month', contentType: 'letter' },

// Day of the month
d: 'day',
dd: 'day',

// Meridiem
a: 'meridiem',
aa: 'meridiem',
aaa: 'meridiem',

// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',

// Minutes
mm: 'minutes',

// Seconds
ss: 'seconds',
a: 'meridiem',
aa: 'meridiem',
aaa: 'meridiem',
};

export class AdapterDateFnsJalali
Expand Down
19 changes: 17 additions & 2 deletions packages/x-date-pickers/src/AdapterDayjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,43 @@ const localeNotFoundWarning = buildWarning([
]);

const formatTokenMap: FieldFormatTokenMap = {
// Year
YY: 'year',
YYYY: 'year',

// Month
M: 'month',
MM: 'month',
MMM: { sectionType: 'month', contentType: 'letter' },
MMMM: { sectionType: 'month', contentType: 'letter' },

// Day of the month
D: 'day',
DD: 'day',

// Day of the week
d: 'weekDay',
dd: { sectionType: 'weekDay', contentType: 'letter' },
ddd: { sectionType: 'weekDay', contentType: 'letter' },
dddd: { sectionType: 'weekDay', contentType: 'letter' },

// Meridiem
A: 'meridiem',
a: 'meridiem',

// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',

// Minutes
m: 'minutes',
mm: 'minutes',

// Seconds
s: 'seconds',
ss: 'seconds',
A: 'meridiem',
a: 'meridiem',
};

interface Opts {
Expand Down
52 changes: 30 additions & 22 deletions packages/x-date-pickers/src/AdapterLuxon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import BaseAdapterLuxon from '@date-io/luxon';
import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';

const formatTokenMap: FieldFormatTokenMap = {
s: 'seconds',
ss: 'seconds',

m: 'minutes',
mm: 'minutes',

H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',
// Year
y: 'year',
yy: 'year',
yyyy: 'year',

a: 'meridiem',
// Month
L: 'month',
LL: 'month',
LLL: { sectionType: 'month', contentType: 'letter' },
LLLL: { sectionType: 'month', contentType: 'letter' },
M: 'month',
MM: 'month',
MMM: { sectionType: 'month', contentType: 'letter' },
MMMM: { sectionType: 'month', contentType: 'letter' },

// Day of the month
d: 'day',
dd: 'day',

// Day of the week
c: 'weekDay',
ccc: { sectionType: 'weekDay', contentType: 'letter' },
cccc: { sectionType: 'weekDay', contentType: 'letter' },
Expand All @@ -29,18 +33,22 @@ const formatTokenMap: FieldFormatTokenMap = {
EEEE: { sectionType: 'weekDay', contentType: 'letter' },
EEEEE: { sectionType: 'weekDay', contentType: 'letter' },

L: 'month',
LL: 'month',
LLL: { sectionType: 'month', contentType: 'letter' },
LLLL: { sectionType: 'month', contentType: 'letter' },
M: 'month',
MM: 'month',
MMM: { sectionType: 'month', contentType: 'letter' },
MMMM: { sectionType: 'month', contentType: 'letter' },
// Meridiem
a: 'meridiem',

y: 'year',
yy: 'year',
yyyy: 'year',
// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',

// Minutes
m: 'minutes',
mm: 'minutes',

// Seconds
s: 'seconds',
ss: 'seconds',
};

export class AdapterLuxon extends BaseAdapterLuxon implements MuiPickersAdapter<DateTime> {
Expand Down
18 changes: 9 additions & 9 deletions packages/x-date-pickers/src/AdapterMoment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';

// From https://momentjs.com/docs/#/displaying/format/
const formatTokenMap: FieldFormatTokenMap = {
// Year
Y: 'year',
YY: 'year',
YYYY: 'year',

// Month
M: 'month',
MM: 'month',
Expand All @@ -23,28 +28,23 @@ const formatTokenMap: FieldFormatTokenMap = {
ddd: { sectionType: 'weekDay', contentType: 'letter' },
dddd: { sectionType: 'weekDay', contentType: 'letter' },

// Year
Y: 'year',
YY: 'year',
YYYY: 'year',

// AM / PM
// Meridiem
A: 'meridiem',
a: 'meridiem',

// Hour
// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',
k: 'hours',
kk: 'hours',

// Minute
// Minutes
m: 'minutes',
mm: 'minutes',

// Second
// Seconds
s: 'seconds',
ss: 'seconds',
};
Expand Down
20 changes: 10 additions & 10 deletions packages/x-date-pickers/src/AdapterMomentHijri/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ import { FieldFormatTokenMap, MuiPickersAdapter } from '../internals/models';

// From https://momentjs.com/docs/#/displaying/format/
const formatTokenMap: FieldFormatTokenMap = {
// Year
iY: 'year',
iYY: 'year',
iYYYY: 'year',

// Month
iM: 'month',
iMM: 'month',
iMMM: { sectionType: 'month', contentType: 'letter' },
iMMMM: { sectionType: 'month', contentType: 'letter' },

// Day of Month
// Day of the month
iD: 'day',
iDD: 'day',

// Year
iY: 'year',
iYY: 'year',
iYYYY: 'year',

// AM / PM
// Meridiem
A: 'meridiem',
a: 'meridiem',

// Hour
// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',
k: 'hours',
kk: 'hours',

// Minute
// Minutes
m: 'minutes',
mm: 'minutes',

// Second
// Seconds
s: 'seconds',
ss: 'seconds',
};
Expand Down
18 changes: 9 additions & 9 deletions packages/x-date-pickers/src/AdapterMomentJalaali/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ type Moment = defaultMoment.Moment;

// From https://momentjs.com/docs/#/displaying/format/
const formatTokenMap: FieldFormatTokenMap = {
// Year
jYY: 'year',
jYYYY: 'year',

// Month
jM: 'month',
jMM: 'month',
jMMM: { sectionType: 'month', contentType: 'letter' },
jMMMM: { sectionType: 'month', contentType: 'letter' },

// Day of Month
// Day of the month
jD: 'day',
jDD: 'day',

// Year
jYY: 'year',
jYYYY: 'year',

// AM / PM
// Meridiem
A: 'meridiem',
a: 'meridiem',

// Hour
// Hours
H: 'hours',
HH: 'hours',
h: 'hours',
hh: 'hours',
k: 'hours',
kk: 'hours',

// Minute
// Minutes
m: 'minutes',
mm: 'minutes',

// Second
// Seconds
s: 'seconds',
ss: 'seconds',
};
Expand Down