Skip to content

Commit

Permalink
chore: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
YUCLing committed Sep 27, 2024
1 parent 86df915 commit 5ea7616
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions framework/core/js/src/common/utils/dayjsPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
export const customFormats: import('dayjs').PluginFunc = function (_option, c, _factory) {
const proto = c.prototype;
const oldFormat = proto.format;
const proto = c.prototype;
const oldFormat = proto.format;

const t = (format?: string) =>
format?.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1))
const t = (format?: string) => format?.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));

const englishFormats: Record<string, string> = {
F: 'DD MMMM',
FF: 'MMMM YYYY'
};
const englishFormats: Record<string, string> = {
F: 'DD MMMM',
FF: 'MMMM YYYY',
};

proto.format = function(template) {
const { formats = {} } = (this as any).$locale();
const result = template?.replace(/(\[[^\]]+])|(f{1,2}|F{1,2})/g, (_, a, b) => {
const B = b && b.toUpperCase();
return a || formats[b] || englishFormats[b] || t(formats[B]) || t(englishFormats[B]);
});
return oldFormat.call(this, result);
}
}
proto.format = function (template) {
const { formats = {} } = (this as any).$locale();
const result = template?.replace(/(\[[^\]]+])|(f{1,2}|F{1,2})/g, (_, a, b) => {
const B = b && b.toUpperCase();
return a || formats[b] || englishFormats[b] || t(formats[B]) || t(englishFormats[B]);
});
return oldFormat.call(this, result);
};
};

0 comments on commit 5ea7616

Please sign in to comment.