135 lines
3.1 KiB
JavaScript
135 lines
3.1 KiB
JavaScript
|
import { buildMatchFn } from "../../_lib/buildMatchFn.mjs";
|
||
|
import { buildMatchPatternFn } from "../../_lib/buildMatchPatternFn.mjs";
|
||
|
|
||
|
const matchOrdinalNumberPattern = /^(\d+)(\.)/i;
|
||
|
const parseOrdinalNumberPattern = /\d+/i;
|
||
|
|
||
|
const matchEraPatterns = {
|
||
|
narrow: /^(e|j)/i,
|
||
|
abbreviated: /^(eaa.|jaa.)/i,
|
||
|
wide: /^(ennen ajanlaskun alkua|jälkeen ajanlaskun alun)/i,
|
||
|
};
|
||
|
const parseEraPatterns = {
|
||
|
any: [/^e/i, /^j/i],
|
||
|
};
|
||
|
|
||
|
const matchQuarterPatterns = {
|
||
|
narrow: /^[1234]/i,
|
||
|
abbreviated: /^q[1234]/i,
|
||
|
wide: /^[1234]\.? kvartaali/i,
|
||
|
};
|
||
|
const parseQuarterPatterns = {
|
||
|
any: [/1/i, /2/i, /3/i, /4/i],
|
||
|
};
|
||
|
|
||
|
const matchMonthPatterns = {
|
||
|
narrow: /^[thmkeslj]/i,
|
||
|
abbreviated:
|
||
|
/^(tammi|helmi|maalis|huhti|touko|kesä|heinä|elo|syys|loka|marras|joulu)/i,
|
||
|
wide: /^(tammikuu|helmikuu|maaliskuu|huhtikuu|toukokuu|kesäkuu|heinäkuu|elokuu|syyskuu|lokakuu|marraskuu|joulukuu)(ta)?/i,
|
||
|
};
|
||
|
const parseMonthPatterns = {
|
||
|
narrow: [
|
||
|
/^t/i,
|
||
|
/^h/i,
|
||
|
/^m/i,
|
||
|
/^h/i,
|
||
|
/^t/i,
|
||
|
/^k/i,
|
||
|
/^h/i,
|
||
|
/^e/i,
|
||
|
/^s/i,
|
||
|
/^l/i,
|
||
|
/^m/i,
|
||
|
/^j/i,
|
||
|
],
|
||
|
|
||
|
any: [
|
||
|
/^ta/i,
|
||
|
/^hel/i,
|
||
|
/^maa/i,
|
||
|
/^hu/i,
|
||
|
/^to/i,
|
||
|
/^k/i,
|
||
|
/^hei/i,
|
||
|
/^e/i,
|
||
|
/^s/i,
|
||
|
/^l/i,
|
||
|
/^mar/i,
|
||
|
/^j/i,
|
||
|
],
|
||
|
};
|
||
|
|
||
|
const matchDayPatterns = {
|
||
|
narrow: /^[smtkpl]/i,
|
||
|
short: /^(su|ma|ti|ke|to|pe|la)/i,
|
||
|
abbreviated: /^(sunn.|maan.|tiis.|kesk.|torst.|perj.|la)/i,
|
||
|
wide: /^(sunnuntai|maanantai|tiistai|keskiviikko|torstai|perjantai|lauantai)(na)?/i,
|
||
|
};
|
||
|
const parseDayPatterns = {
|
||
|
narrow: [/^s/i, /^m/i, /^t/i, /^k/i, /^t/i, /^p/i, /^l/i],
|
||
|
any: [/^s/i, /^m/i, /^ti/i, /^k/i, /^to/i, /^p/i, /^l/i],
|
||
|
};
|
||
|
|
||
|
const matchDayPeriodPatterns = {
|
||
|
narrow:
|
||
|
/^(ap|ip|keskiyö|keskipäivä|aamupäivällä|iltapäivällä|illalla|yöllä)/i,
|
||
|
any: /^(ap|ip|keskiyöllä|keskipäivällä|aamupäivällä|iltapäivällä|illalla|yöllä)/i,
|
||
|
};
|
||
|
const parseDayPeriodPatterns = {
|
||
|
any: {
|
||
|
am: /^ap/i,
|
||
|
pm: /^ip/i,
|
||
|
midnight: /^keskiyö/i,
|
||
|
noon: /^keskipäivä/i,
|
||
|
morning: /aamupäivällä/i,
|
||
|
afternoon: /iltapäivällä/i,
|
||
|
evening: /illalla/i,
|
||
|
night: /yöllä/i,
|
||
|
},
|
||
|
};
|
||
|
|
||
|
export const match = {
|
||
|
ordinalNumber: buildMatchPatternFn({
|
||
|
matchPattern: matchOrdinalNumberPattern,
|
||
|
parsePattern: parseOrdinalNumberPattern,
|
||
|
valueCallback: (value) => parseInt(value, 10),
|
||
|
}),
|
||
|
|
||
|
era: buildMatchFn({
|
||
|
matchPatterns: matchEraPatterns,
|
||
|
defaultMatchWidth: "wide",
|
||
|
parsePatterns: parseEraPatterns,
|
||
|
defaultParseWidth: "any",
|
||
|
}),
|
||
|
|
||
|
quarter: buildMatchFn({
|
||
|
matchPatterns: matchQuarterPatterns,
|
||
|
defaultMatchWidth: "wide",
|
||
|
parsePatterns: parseQuarterPatterns,
|
||
|
defaultParseWidth: "any",
|
||
|
valueCallback: (index) => index + 1,
|
||
|
}),
|
||
|
|
||
|
month: buildMatchFn({
|
||
|
matchPatterns: matchMonthPatterns,
|
||
|
defaultMatchWidth: "wide",
|
||
|
parsePatterns: parseMonthPatterns,
|
||
|
defaultParseWidth: "any",
|
||
|
}),
|
||
|
|
||
|
day: buildMatchFn({
|
||
|
matchPatterns: matchDayPatterns,
|
||
|
defaultMatchWidth: "wide",
|
||
|
parsePatterns: parseDayPatterns,
|
||
|
defaultParseWidth: "any",
|
||
|
}),
|
||
|
|
||
|
dayPeriod: buildMatchFn({
|
||
|
matchPatterns: matchDayPeriodPatterns,
|
||
|
defaultMatchWidth: "any",
|
||
|
parsePatterns: parseDayPeriodPatterns,
|
||
|
defaultParseWidth: "any",
|
||
|
}),
|
||
|
};
|