@formatjs/intl-datetimeformat
Advanced tools
Comparing version 6.2.0 to 6.3.0
import { __assign } from "tslib"; | ||
import { invariant } from '@formatjs/ecma402-abstract'; | ||
import { DATE_TIME_PROPS, additionPenalty, removalPenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, } from './utils'; | ||
import { DATE_TIME_PROPS, additionPenalty, removalPenalty, longMorePenalty, shortMorePenalty, shortLessPenalty, longLessPenalty, offsetPenalty, } from './utils'; | ||
/** | ||
@@ -26,2 +26,51 @@ * https://tc39.es/ecma402/#sec-basicformatmatcher | ||
} | ||
else if (prop === 'timeZoneName') { | ||
if (optionsProp === 'short' || optionsProp === 'shortGeneric') { | ||
if (formatProp === 'shortOffset') { | ||
score -= offsetPenalty; | ||
} | ||
else if (formatProp === 'longOffset') { | ||
score -= offsetPenalty + shortMorePenalty; | ||
} | ||
else if (optionsProp === 'short' && formatProp === 'long') { | ||
score -= shortMorePenalty; | ||
} | ||
else if (optionsProp === 'shortGeneric' && | ||
formatProp === 'longGeneric') { | ||
score -= shortMorePenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= removalPenalty; | ||
} | ||
} | ||
else if (optionsProp === 'shortOffset' && | ||
formatProp === 'longOffset') { | ||
score -= shortMorePenalty; | ||
} | ||
else if (optionsProp === 'long' || optionsProp === 'longGeneric') { | ||
if (formatProp === 'longOffset') { | ||
score -= offsetPenalty; | ||
} | ||
else if (formatProp === 'shortOffset') { | ||
score -= offsetPenalty + longLessPenalty; | ||
} | ||
else if (optionsProp === 'long' && formatProp === 'short') { | ||
score -= longLessPenalty; | ||
} | ||
else if (optionsProp === 'longGeneric' && | ||
formatProp === 'shortGeneric') { | ||
score -= longLessPenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= removalPenalty; | ||
} | ||
} | ||
else if (optionsProp === 'longOffset' && | ||
formatProp === 'shortOffset') { | ||
score -= longLessPenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= removalPenalty; | ||
} | ||
} | ||
else if (optionsProp !== formatProp) { | ||
@@ -28,0 +77,0 @@ var values = void 0; |
@@ -83,4 +83,22 @@ import { TimeClip, } from '@formatjs/ecma402-abstract'; | ||
else if (p === 'dayPeriod') { | ||
// TODO | ||
var f = internalSlots.dayPeriod; | ||
// @ts-ignore | ||
var fv = tm[f]; | ||
result.push({ type: p, value: fv }); | ||
} | ||
else if (p === 'timeZoneName') { | ||
var f = internalSlots.timeZoneName; | ||
var fv = void 0; | ||
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat; | ||
var timeZone = internalSlots.timeZone || getDefaultTimeZone(); | ||
var timeZoneData = timeZoneName[timeZone]; | ||
if (timeZoneData && timeZoneData[f]) { | ||
fv = timeZoneData[f][+tm.inDST]; | ||
} | ||
else { | ||
// Fallback to gmtFormat | ||
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f); | ||
} | ||
result.push({ type: p, value: fv }); | ||
} | ||
else if (DATE_TIME_PROPS.indexOf(p) > -1) { | ||
@@ -122,14 +140,2 @@ var fv = ''; | ||
} | ||
else if (p === 'timeZoneName') { | ||
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat; | ||
var timeZone = internalSlots.timeZone || getDefaultTimeZone(); | ||
var timeZoneData = timeZoneName[timeZone]; | ||
if (timeZoneData && timeZoneData[f]) { | ||
fv = timeZoneData[f][+tm.inDST]; | ||
} | ||
else { | ||
// Fallback to gmtFormat | ||
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f); | ||
} | ||
} | ||
else if (p === 'month') { | ||
@@ -136,0 +142,0 @@ fv = dataLocaleData.month[f][v - 1]; |
@@ -105,3 +105,10 @@ import { CanonicalizeLocaleList, invariant, GetOption, IsValidTimeZoneName, CanonicalizeTimeZoneName, GetNumberOption, } from '@formatjs/ecma402-abstract'; | ||
opt.second = GetOption(options, 'second', 'string', ['2-digit', 'numeric'], undefined); | ||
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', ['short', 'long'], undefined); | ||
opt.timeZoneName = GetOption(options, 'timeZoneName', 'string', [ | ||
'long', | ||
'short', | ||
'longOffset', | ||
'shortOffset', | ||
'longGeneric', | ||
'shortGeneric', | ||
], undefined); | ||
opt.fractionalSecondDigits = GetNumberOption(options, 'fractionalSecondDigits', 1, 3, | ||
@@ -108,0 +115,0 @@ // @ts-expect-error |
@@ -10,2 +10,3 @@ import { IntlDateTimeFormatInternal, TABLE_6 } from '@formatjs/ecma402-abstract'; | ||
export declare const shortMorePenalty = 3; | ||
export declare const offsetPenalty = 1; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -7,5 +7,7 @@ export var DATE_TIME_PROPS = [ | ||
'day', | ||
'dayPeriod', | ||
'hour', | ||
'minute', | ||
'second', | ||
'fractionalSecondDigits', | ||
'timeZoneName', | ||
@@ -20,1 +22,2 @@ ]; | ||
export var shortMorePenalty = 3; | ||
export var offsetPenalty = 1; |
{ | ||
"name": "@formatjs/intl-datetimeformat", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "Intl.DateTimeFormat polyfill", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@formatjs/ecma402-abstract": "1.12.0", | ||
"@formatjs/ecma402-abstract": "1.13.0", | ||
"@formatjs/intl-localematcher": "0.2.31", | ||
@@ -32,4 +32,4 @@ "tslib": "2.4.0" | ||
"@formatjs/intl-getcanonicallocales": "2.0.4", | ||
"@formatjs/intl-locale": "3.0.6" | ||
"@formatjs/intl-locale": "3.0.7" | ||
} | ||
} |
@@ -29,2 +29,51 @@ "use strict"; | ||
} | ||
else if (prop === 'timeZoneName') { | ||
if (optionsProp === 'short' || optionsProp === 'shortGeneric') { | ||
if (formatProp === 'shortOffset') { | ||
score -= utils_1.offsetPenalty; | ||
} | ||
else if (formatProp === 'longOffset') { | ||
score -= utils_1.offsetPenalty + utils_1.shortMorePenalty; | ||
} | ||
else if (optionsProp === 'short' && formatProp === 'long') { | ||
score -= utils_1.shortMorePenalty; | ||
} | ||
else if (optionsProp === 'shortGeneric' && | ||
formatProp === 'longGeneric') { | ||
score -= utils_1.shortMorePenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= utils_1.removalPenalty; | ||
} | ||
} | ||
else if (optionsProp === 'shortOffset' && | ||
formatProp === 'longOffset') { | ||
score -= utils_1.shortMorePenalty; | ||
} | ||
else if (optionsProp === 'long' || optionsProp === 'longGeneric') { | ||
if (formatProp === 'longOffset') { | ||
score -= utils_1.offsetPenalty; | ||
} | ||
else if (formatProp === 'shortOffset') { | ||
score -= utils_1.offsetPenalty + utils_1.longLessPenalty; | ||
} | ||
else if (optionsProp === 'long' && formatProp === 'short') { | ||
score -= utils_1.longLessPenalty; | ||
} | ||
else if (optionsProp === 'longGeneric' && | ||
formatProp === 'shortGeneric') { | ||
score -= utils_1.longLessPenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= utils_1.removalPenalty; | ||
} | ||
} | ||
else if (optionsProp === 'longOffset' && | ||
formatProp === 'shortOffset') { | ||
score -= utils_1.longLessPenalty; | ||
} | ||
else if (optionsProp !== formatProp) { | ||
score -= utils_1.removalPenalty; | ||
} | ||
} | ||
else if (optionsProp !== formatProp) { | ||
@@ -31,0 +80,0 @@ var values = void 0; |
@@ -86,4 +86,22 @@ "use strict"; | ||
else if (p === 'dayPeriod') { | ||
// TODO | ||
var f = internalSlots.dayPeriod; | ||
// @ts-ignore | ||
var fv = tm[f]; | ||
result.push({ type: p, value: fv }); | ||
} | ||
else if (p === 'timeZoneName') { | ||
var f = internalSlots.timeZoneName; | ||
var fv = void 0; | ||
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat; | ||
var timeZone = internalSlots.timeZone || getDefaultTimeZone(); | ||
var timeZoneData = timeZoneName[timeZone]; | ||
if (timeZoneData && timeZoneData[f]) { | ||
fv = timeZoneData[f][+tm.inDST]; | ||
} | ||
else { | ||
// Fallback to gmtFormat | ||
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f); | ||
} | ||
result.push({ type: p, value: fv }); | ||
} | ||
else if (utils_1.DATE_TIME_PROPS.indexOf(p) > -1) { | ||
@@ -125,14 +143,2 @@ var fv = ''; | ||
} | ||
else if (p === 'timeZoneName') { | ||
var timeZoneName = dataLocaleData.timeZoneName, gmtFormat = dataLocaleData.gmtFormat, hourFormat = dataLocaleData.hourFormat; | ||
var timeZone = internalSlots.timeZone || getDefaultTimeZone(); | ||
var timeZoneData = timeZoneName[timeZone]; | ||
if (timeZoneData && timeZoneData[f]) { | ||
fv = timeZoneData[f][+tm.inDST]; | ||
} | ||
else { | ||
// Fallback to gmtFormat | ||
fv = offsetToGmtString(gmtFormat, hourFormat, tm.timeZoneOffset, f); | ||
} | ||
} | ||
else if (p === 'month') { | ||
@@ -139,0 +145,0 @@ fv = dataLocaleData.month[f][v - 1]; |
@@ -108,3 +108,10 @@ "use strict"; | ||
opt.second = (0, ecma402_abstract_1.GetOption)(options, 'second', 'string', ['2-digit', 'numeric'], undefined); | ||
opt.timeZoneName = (0, ecma402_abstract_1.GetOption)(options, 'timeZoneName', 'string', ['short', 'long'], undefined); | ||
opt.timeZoneName = (0, ecma402_abstract_1.GetOption)(options, 'timeZoneName', 'string', [ | ||
'long', | ||
'short', | ||
'longOffset', | ||
'shortOffset', | ||
'longGeneric', | ||
'shortGeneric', | ||
], undefined); | ||
opt.fractionalSecondDigits = (0, ecma402_abstract_1.GetNumberOption)(options, 'fractionalSecondDigits', 1, 3, | ||
@@ -111,0 +118,0 @@ // @ts-expect-error |
@@ -10,2 +10,3 @@ import { IntlDateTimeFormatInternal, TABLE_6 } from '@formatjs/ecma402-abstract'; | ||
export declare const shortMorePenalty = 3; | ||
export declare const offsetPenalty = 1; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0; | ||
exports.offsetPenalty = exports.shortMorePenalty = exports.shortLessPenalty = exports.longMorePenalty = exports.longLessPenalty = exports.differentNumericTypePenalty = exports.additionPenalty = exports.removalPenalty = exports.DATE_TIME_PROPS = void 0; | ||
exports.DATE_TIME_PROPS = [ | ||
@@ -10,5 +10,7 @@ 'weekday', | ||
'day', | ||
'dayPeriod', | ||
'hour', | ||
'minute', | ||
'second', | ||
'fractionalSecondDigits', | ||
'timeZoneName', | ||
@@ -23,1 +25,2 @@ ]; | ||
exports.shortMorePenalty = 3; | ||
exports.offsetPenalty = 1; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31244528
122063
+ Added@formatjs/ecma402-abstract@1.13.0(transitive)
- Removed@formatjs/ecma402-abstract@1.12.0(transitive)