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

Add a text-to-number coercion #1899

Merged
merged 4 commits into from Oct 30, 2022
Merged

Add a text-to-number coercion #1899

merged 4 commits into from Oct 30, 2022

Conversation

jahav
Copy link
Member

@jahav jahav commented Oct 30, 2022

This was not fun.

I can just image a that conversation when they were writing the specification:

Technical writer: So I got a task to document type coercion for the Open XML standard. How does it work?
Dev: That's a deep hole. We have number, fractions, currencies, percents, time spans and dates. We use our own parser that accepts a lot of inputs that are just not generally considered fine, like 1000 hours in a date and so on.
Technical writer: Can we utilize some other standards?
Dev: Not really, this goes way back to first versions in 1980s and 90s, there wasn't even unicode back then. Each country had it's own separate build with a baked-in culture, so it couldn't change parsing methods on the fly.
Technical writer: What if I open an excel from US that has a date in a format 'MM/dd/yyyy' and open it different country with a different date format?
Dev: Yeah, the date won't be coerced to number in the new country.
Technical writer: Are date formats described in some other official specification? ISO8601... anything?
Dev: Don't think so. Just our internal docs.
Technical writers: What about numbers? They have pretty well established grammar.
Dev: Yeah, there are some not-so-accepted features, like a allowed whitespacespace between a sign and a number, like "- 1"
Technical writer: So the coercion is a culture specific and doesn't conform to any kind of public standard, thanks to compatibility going back decades.
Dev: That pretty much sums it up.
Technical writer: Screw it. This will do.

An implementation is permitted to provide an implicit conversion from string-constant to number. However, the
rules by which such conversions take place are implementation-defined. [Example: An implementation might
choose to accept "123"+10 by converting the string "123" to the number 123. Such conversions might be locale-
specific in that a string-constant such as "10,56" might be converted to 10.56 in some locales, but not in others,
depending on the radix point character. end example]

Related to #1891.

@jahav jahav added this to the v0.97.1 milestone Oct 30, 2022
…tandard format d-mmm-yyyy, 'd-mmm', 'mmm-d', mmm-yy', 'h:mm AM/PM', 'h:mm:ss AM/PM', short date for culture.
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

Successfully merging this pull request may close these issues.

None yet

1 participant