added week and months to unit plugin
This commit is contained in:
parent
37b300b8e9
commit
602e92f986
2 changed files with 13 additions and 3 deletions
|
|
@ -29,7 +29,7 @@ const TEMP_UNIT_DEG = '°\\s*[FfCc]';
|
|||
const TEMP_UNIT_BARE = '[FfCc]';
|
||||
const WEIGHT_UNIT = '(?:kg|g|oz|lbs?|ounces?|pounds?)';
|
||||
const VOLUME_UNIT = '(?:cups?|tablespoons?|table\\s+spoons?|tbsp|teaspoons?|tsp|ml|mL|L|liters?|litres?|quarts?|gallons?|pints?|fl\\.?\\s*oz|fluid\\s+ounces?|parts\\s+by\\s+(?:volume|weight))';
|
||||
const TIME_UNIT = '(?:minutes?|mins?|hours?|hrs?|days?|seconds?|secs?)';
|
||||
const TIME_UNIT = '(?:minutes?|mins?|hours?|hrs?|days?|weeks?|months?|seconds?|secs?)';
|
||||
const DIM_UNIT = '(?:inch(?:es)?|in\\.?|cm|mm)';
|
||||
|
||||
// ─── Amount Parsing ───────────────────────────────────────
|
||||
|
|
@ -189,6 +189,8 @@ function normalizeUnit(unit) {
|
|||
if (/^minutes?$/.test(u) || /^mins?$/.test(u)) return 'minute';
|
||||
if (/^hours?$/.test(u) || /^hrs?$/.test(u)) return 'hour';
|
||||
if (/^days?$/.test(u)) return 'day';
|
||||
if (/^weeks?$/.test(u)) return 'week';
|
||||
if (/^months?$/.test(u)) return 'month';
|
||||
if (/^seconds?$/.test(u) || /^secs?$/.test(u)) return 'second';
|
||||
|
||||
// Dimension units
|
||||
|
|
@ -206,7 +208,7 @@ function unitType(normalizedUnit) {
|
|||
if (['°F', '°C'].includes(normalizedUnit)) return 'temperature';
|
||||
if (['g', 'kg', 'oz', 'lb'].includes(normalizedUnit)) return 'weight';
|
||||
if (['cup', 'tablespoon', 'teaspoon', 'ml', 'L', 'quart', 'gallon', 'pint', 'fl oz', 'parts by volume', 'parts by weight'].includes(normalizedUnit)) return 'volume';
|
||||
if (['minute', 'hour', 'day', 'second'].includes(normalizedUnit)) return 'time';
|
||||
if (['minute', 'hour', 'day', 'week', 'month', 'second'].includes(normalizedUnit)) return 'time';
|
||||
if (['inch', 'cm', 'mm', 'ft'].includes(normalizedUnit)) return 'dimension';
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,11 @@ function unitLabel(unit, plural) {
|
|||
'°F': '°F', '°C': '°C',
|
||||
'inch': plural ? 'inches' : 'inch',
|
||||
'cm': 'cm', 'mm': 'mm',
|
||||
'minute': 'min', 'hour': 'hr', 'day': plural ? 'days' : 'day',
|
||||
'minute': 'min',
|
||||
'hour': 'hr',
|
||||
'day': plural ? 'days' : 'day',
|
||||
'week': plural ? 'weeks' : 'week',
|
||||
'month': plural ? 'months' : 'month',
|
||||
'second': plural ? 'seconds' : 'sec',
|
||||
'parts by volume': 'parts by volume',
|
||||
'parts by weight': 'parts by weight',
|
||||
|
|
@ -211,6 +215,8 @@ function toMinutes(value, unit) {
|
|||
|
||||
function collapsedTime(value, unit) {
|
||||
if (unit === 'day') return formatValueUnit(value, 'day');
|
||||
if (unit === 'week') return formatValueUnit(value, 'week');
|
||||
if (unit === 'month') return formatValueUnit(value, 'month');
|
||||
if (unit === 'second') return formatValueUnit(value, 'second');
|
||||
const mins = toMinutes(value, unit);
|
||||
if (mins === null) return formatValueUnit(value, unit);
|
||||
|
|
@ -219,6 +225,8 @@ function collapsedTime(value, unit) {
|
|||
|
||||
function expandedTime(value, unit) {
|
||||
if (unit === 'day') return formatValueUnit(value, 'day');
|
||||
if (unit === 'week') return formatValueUnit(value, 'week');
|
||||
if (unit === 'month') return formatValueUnit(value, 'month');
|
||||
if (unit === 'second') return formatValueUnit(value, 'second');
|
||||
const mins = toMinutes(value, unit);
|
||||
if (mins === null) return formatValueUnit(value, unit);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue