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
40 lines
923 B
Plaintext
40 lines
923 B
Plaintext
import { Parser } from "../Parser.mjs";
|
|
|
|
export class EraParser extends Parser {
|
|
priority = 140;
|
|
|
|
parse(dateString, token, match) {
|
|
switch (token) {
|
|
// AD, BC
|
|
case "G":
|
|
case "GG":
|
|
case "GGG":
|
|
return (
|
|
match.era(dateString, { width: "abbreviated" }) ||
|
|
match.era(dateString, { width: "narrow" })
|
|
);
|
|
|
|
// A, B
|
|
case "GGGGG":
|
|
return match.era(dateString, { width: "narrow" });
|
|
// Anno Domini, Before Christ
|
|
case "GGGG":
|
|
default:
|
|
return (
|
|
match.era(dateString, { width: "wide" }) ||
|
|
match.era(dateString, { width: "abbreviated" }) ||
|
|
match.era(dateString, { width: "narrow" })
|
|
);
|
|
}
|
|
}
|
|
|
|
set(date, flags, value) {
|
|
flags.era = value;
|
|
date.setFullYear(value, 0, 1);
|
|
date.setHours(0, 0, 0, 0);
|
|
return date;
|
|
}
|
|
|
|
incompatibleTokens = ["R", "u", "t", "T"];
|
|
}
|