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

Return formula result datatype #31

Open
LesterLyu opened this issue Dec 6, 2020 · 2 comments
Open

Return formula result datatype #31

LesterLyu opened this issue Dec 6, 2020 · 2 comments
Projects

Comments

@LesterLyu
Copy link
Owner

LesterLyu commented Dec 6, 2020

Why?

People need to know the format of the formula result to visulize the result.

Example 1:

DATE(2000, 1, 1) results in

  • 36526 in General format
  • 1/1/2000 in Date format.
    Internally, the value is being stored as a number 36526 (or so-called excel serial number), but there is a way to store and propagate the type of the value when evaluating the formula DATE(2000, 1, 1). Thus, we can tell users that the result is a Date.

Example 2:

DATE(CONCAT(200, 0), 1, 1) returns a date value/ serial number.
CONCAT(200, 0) always return a string (or error), DATE(CONCAT(200, 0), 1, 1) always return a date (or error).

Example 3:

CONCATE(DATE(2000, 1, 1)) returns a string.

Questions

Do we need to propagate the type internally?

It is unnecessary. We only need to know the out-most function name, since the out-most function determines the result type.

How many types are there?

So far, I discovered only Date and General. General can be JavaScript Number, String, Boolean.

How about some formulas returning a cell reference, range reference, array? Should we tell the user what we returning?

How about a simple reference =A1, where A1 has a formula type Date?

We should know the type of the given cell, but how?

Should we provide a format function in the result wrapper, which is basically SSF.format but only takes a format string?

Do we use a pure JS object to wrap the formula result, or a class?

class may use more memory. Generating more unnecessary data → Invoke Garbage Collector more frequently.

More questions?

Proposing

Currently I don't have a clear idea of the implementation, we must think of all the questions above carefully.

Instead of returning the value directly, we return an object that wraps the result and add information about the type, e.g., Date, or Excel Serial Number.

@LesterLyu LesterLyu added this to To do in V2 Dec 6, 2020
@LesterLyu
Copy link
Owner Author

@rmdort Please take a look.

@rmdort
Copy link
Contributor

rmdort commented Dec 6, 2020

Looks great. A few things if not covered.

  1. It would be good if we return specific types rather than General, since each function already knows the resultype it returns.
  2. IMO, i expect resulttype only for functions and not for pure cell references.
  3. I don't think the parser should format the result. User can now do that easily since they have access to resulttype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
V2
To do
Development

No branches or pull requests

2 participants