Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globalize-runtime cannot have two unit formatters with same options but different number formatters #704

Closed
mattyork opened this issue Mar 22, 2017 · 1 comment

Comments

@mattyork
Copy link
Contributor

Globalize version: 1.2.3
Globalize compiler version: v0.2.4

Example code (might not compile, but hopefully illustrates the point):

// compilation time - note that the only difference in formatters is the number formatter options
const unitFormatOptions1 = { numberFormatter: globalizeInstance.numberFormatter({minimumIntegerDigits: 1}) };
const unitFormatOptions2 = { numberFormatter: globalizeInstance.numberFormatter({minimumIntegerDigits: 2}) };
compileFormatters([
  globalizeInstance.unitFormatter('hour', unitFormatOptions1),
  globalizeInstance.unitFormatter('hour', unitFormatOptions2)
]);


// ... now to the runtime
const x = globalizeInstance.formatUnit(3, 'hour', unitFormatOptions1); 
const y = globalizeInstance.formatUnit(3, 'hour', unitFormatOptions2);

Expected: x == "3" and y== "03"
Actual: x == "3" and y == "3"

The problem is that the unit formatter takes a number formatter (a function) as one of its options, but the runtime keys are generated by JSON.stringifying the options (see here), and JSON.stringify stringifies functions as empty string.

So, the runtime key is resolved to the same thing in both formatters, even though they have different number formatters.

@mattyork
Copy link
Contributor Author

#705 is related and may have the same solution

nkovacs added a commit to nkovacs/globalize that referenced this issue May 11, 2017
JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes globalizejs#704
nkovacs added a commit to nkovacs/globalize that referenced this issue May 11, 2017
JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes globalizejs#704
nkovacs added a commit to nkovacs/globalize-compiler that referenced this issue May 11, 2017
nkovacs added a commit to nkovacs/globalize that referenced this issue May 11, 2017
JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes globalizejs#704
nkovacs added a commit to nkovacs/globalize-compiler that referenced this issue May 11, 2017
nkovacs added a commit to nkovacs/globalize that referenced this issue May 22, 2017
JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes globalizejs#704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant