Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
65 lines
1.6 KiB
Plaintext
65 lines
1.6 KiB
Plaintext
const dateLongFormatter = (pattern, formatLong) => {
|
|
switch (pattern) {
|
|
case "P":
|
|
return formatLong.date({ width: "short" });
|
|
case "PP":
|
|
return formatLong.date({ width: "medium" });
|
|
case "PPP":
|
|
return formatLong.date({ width: "long" });
|
|
case "PPPP":
|
|
default:
|
|
return formatLong.date({ width: "full" });
|
|
}
|
|
};
|
|
|
|
const timeLongFormatter = (pattern, formatLong) => {
|
|
switch (pattern) {
|
|
case "p":
|
|
return formatLong.time({ width: "short" });
|
|
case "pp":
|
|
return formatLong.time({ width: "medium" });
|
|
case "ppp":
|
|
return formatLong.time({ width: "long" });
|
|
case "pppp":
|
|
default:
|
|
return formatLong.time({ width: "full" });
|
|
}
|
|
};
|
|
|
|
const dateTimeLongFormatter = (pattern, formatLong) => {
|
|
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
const datePattern = matchResult[1];
|
|
const timePattern = matchResult[2];
|
|
|
|
if (!timePattern) {
|
|
return dateLongFormatter(pattern, formatLong);
|
|
}
|
|
|
|
let dateTimeFormat;
|
|
|
|
switch (datePattern) {
|
|
case "P":
|
|
dateTimeFormat = formatLong.dateTime({ width: "short" });
|
|
break;
|
|
case "PP":
|
|
dateTimeFormat = formatLong.dateTime({ width: "medium" });
|
|
break;
|
|
case "PPP":
|
|
dateTimeFormat = formatLong.dateTime({ width: "long" });
|
|
break;
|
|
case "PPPP":
|
|
default:
|
|
dateTimeFormat = formatLong.dateTime({ width: "full" });
|
|
break;
|
|
}
|
|
|
|
return dateTimeFormat
|
|
.replace("{{date}}", dateLongFormatter(datePattern, formatLong))
|
|
.replace("{{time}}", timeLongFormatter(timePattern, formatLong));
|
|
};
|
|
|
|
export const longFormatters = {
|
|
p: timeLongFormatter,
|
|
P: dateTimeLongFormatter,
|
|
};
|