handsontable / handsontable/hyperformula
Improve date/time parsing and serialization (was: Refactor `parseDateTime` and `stringifyDate`)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.8k
- Forks
- 171
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 7
Description
Description
Adding DateTime #229 exposed a problem with =TEXT() function. From what I've seen [1] the TEXT function can do a lot more than date and time. So the first problem is that it's located in DatePlugin.ts:
stringifyDate
That makes an assumption we should have stringifyDate callback as an option. This probably should be a formatter(value: string, format: string) that could handle any format TEXT (and any other) would like to stringify. One callback, because we don't know all the formats and it would be hard to categorize them.
This way we can avoid writing complicated number formatter, percentage formatter, fraction formatter and others [2]. This will save us time and work (at this stage) to implement all possible formats. To achieve compatibility with other spreadsheet apps we will need them or an easy way (described in the docs) how this can be done with custom formatter callback.
parseDateTime
The function that works in reverse to TEXT is =VALUE()[3] which takes a string and parses it to a numerical value. This function should be the main consumer of parseDateTime function in the new form. Or a series of callbacks as we spoke with @izulin
There may be multiple formats that VALUE or other APIs (setCellValue, buildFromArray) may have to parse. To not include everything into the engine we can expose a parser function and let the developers fill the gap with a module (moment.js and similar) that perfectly fits their needs.
VALUE is locale dependant as well so this will be the best solution and allow end-developers to implement their own culture logic.
XL:

ODFF:

Basically, the currency and dates and fractions are the same to TEXT but the function works other way, parses instead formatting. It does not accept format, just tryies all the formats that are known to the spreadsheet app and returns value.
TODO
- Implement TEXT function that can handle all formats (with external callback)
- Implement VALUE function that can handle the same formats (with external callback)
Links
[1] https://support.office.com/en-us/article/TEXT-function-20D5AC4D-7B94-49FD-BB38-93D29371225C
[2] https://help.libreoffice.org/6.4/en-US/text/shared/01/05020301.html
[3] https://docs.oasis-open.org/office/OpenDocument/v1.3/csprd02/part4-formula/OpenDocument-v1.3-csprd02-part4-formula.html#__RefHeading__1018410_715980110
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/interpreter/plugin/DatePlugin.ts at the current TEXT-related implementation, then read the TODO and the linked TEXT and VALUE specifications. Trace how stringifyDate and parseDateTime are used before defining the callback boundaries. Done means TEXT and VALUE support the requested externally supplied formatting and parsing behavior without assuming a fixed set of formats.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100