xlcalculator icon indicating copy to clipboard operation
xlcalculator copied to clipboard

Function TODAY returns a datetime but should return a serial number of date.

Open bradbase opened this issue 4 years ago • 2 comments

Currently;

now = datetime.datetime.now

@xl.register()
def TODAY() -> func_xltypes.XlDateTime:
    """Returns the serial number of the current date.

    https://support.office.com/en-us/article/
        today-function-5eb3078d-a82c-4736-8930-2f51a028fdd9
    """
    return now()

Needs to be

now = datetime.datetime.now

@xl.register()
def TODAY() -> func_xltypes.XlNumber:
    """Returns the serial number of the current date.

    https://support.office.com/en-us/article/
        today-function-5eb3078d-a82c-4736-8930-2f51a028fdd9
    """
    date_and_time = now()
    date = date_and_time.replace(
        hour=0, minute=0, second=0, microsecond=0)
    return utils.datetime_to_number(date)

bradbase avatar Nov 11 '20 11:11 bradbase

I would advise you strongly against that. If you return integers for dates that you need to capture somewhere, somehow that the cell is to be formatted as a date. We might need an xlcalculator Date/Time type that knows how to convert itself to a number if needed, but I thought we had that already.

strichter avatar Nov 11 '20 12:11 strichter

There are util functions converting serial/date and back.

I'l reassess my approach

bradbase avatar Nov 11 '20 13:11 bradbase