xlcalculator icon indicating copy to clipboard operation
xlcalculator copied to clipboard

function DATE returns a datetime but should return a number (serial)

Open bradbase opened this issue 4 years ago • 4 comments

Currently;

@xl.register()
@xl.validate_args
def DATE(
        year: func_xltypes.XlNumber,
        month: func_xltypes.XlNumber,
        day: func_xltypes.XlNumber
) -> func_xltypes.XlDateTime:
    """Returns the sequential serial number that represents a particular date.

    https://support.office.com/en-us/article/
        date-function-e36c0c8c-4104-49da-ab83-82328b832349
    """

Should return

@xl.register()
@xl.validate_args
def DATE(
        year: func_xltypes.XlNumber,
        month: func_xltypes.XlNumber,
        day: func_xltypes.XlNumber
) -> func_xltypes.XlNumber:
    """Returns the sequential serial number that represents a particular date.

    https://support.office.com/en-us/article/
        date-function-e36c0c8c-4104-49da-ab83-82328b832349
    """

bradbase avatar Nov 11 '20 12:11 bradbase

Then you have to remove the concept of XlDateTime from the code completely and somehow manage that with formatters. XlDateTime is definitely the right return type and it knows how to convert itself to a number for algebraic operations.

strichter avatar Nov 11 '20 12:11 strichter

Fair enough.

You are correct. func_xltypes.DateTime has an int.

bradbase avatar Nov 11 '20 13:11 bradbase

I've not thought it through completely but sticking with that paradigm I think there we may need to consider adding an XLTime datatype. Excel has a datatype for time and the function TIME is supposed to return a decimal which is probably best managed in a similar way DATE manages the serial integer.

bradbase avatar Nov 11 '20 13:11 bradbase

Tools down for tonight before I make an awful mess.

bradbase avatar Nov 11 '20 13:11 bradbase