Initial commit
This commit is contained in:
54
node_modules/date-fns/parse/_lib/parsers/DayPeriodParser.mjs
generated
vendored
Normal file
54
node_modules/date-fns/parse/_lib/parsers/DayPeriodParser.mjs
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
import { Parser } from "../Parser.mjs";
|
||||
import { dayPeriodEnumToHours } from "../utils.mjs";
|
||||
|
||||
// in the morning, in the afternoon, in the evening, at night
|
||||
export class DayPeriodParser extends Parser {
|
||||
priority = 80;
|
||||
|
||||
parse(dateString, token, match) {
|
||||
switch (token) {
|
||||
case "B":
|
||||
case "BB":
|
||||
case "BBB":
|
||||
return (
|
||||
match.dayPeriod(dateString, {
|
||||
width: "abbreviated",
|
||||
context: "formatting",
|
||||
}) ||
|
||||
match.dayPeriod(dateString, {
|
||||
width: "narrow",
|
||||
context: "formatting",
|
||||
})
|
||||
);
|
||||
|
||||
case "BBBBB":
|
||||
return match.dayPeriod(dateString, {
|
||||
width: "narrow",
|
||||
context: "formatting",
|
||||
});
|
||||
case "BBBB":
|
||||
default:
|
||||
return (
|
||||
match.dayPeriod(dateString, {
|
||||
width: "wide",
|
||||
context: "formatting",
|
||||
}) ||
|
||||
match.dayPeriod(dateString, {
|
||||
width: "abbreviated",
|
||||
context: "formatting",
|
||||
}) ||
|
||||
match.dayPeriod(dateString, {
|
||||
width: "narrow",
|
||||
context: "formatting",
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
set(date, _flags, value) {
|
||||
date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
||||
return date;
|
||||
}
|
||||
|
||||
incompatibleTokens = ["a", "b", "t", "T"];
|
||||
}
|
||||
Reference in New Issue
Block a user