Skip to content

WISH: date1 - date2 to return time! #181

@hiiamboris

Description

@hiiamboris

We have this functionality today covered by the difference native, which is the only set native that accepts a scalar (an exception).

Usually when we deal with dates exclusively it's not a big deal to write difference a b instead of a - b. But when I'm trying to support dates as part of a larger typeset, they require an exception every time (which I find boring).

In particular, these scalar value types can be mapped to a plot axis: [integer! float! pair! percent! time! date! money!]. The same math works for all of them, except date!. In the instead of subtraction I have to write a wrapper, e.g.:

subtract': func [a [scalar!] b [scalar!]] [
    either date? a [difference a b] [a - b]
]

E.g. to map a value from A..B into C..D:

AB: subtract' B A
CD: subtract' D C
x: (subtract' x A) / AB * CD + C

subtract is the only math operation that doesn't work as expected.

I propose that common subtraction should work on dates, producing a time!. With a bit of care, the same expressions then could be used for all of the supported types.

date + n, date - n may still work as it is, adding/subtracting n days.

In a (rare) case when days are required, one can write date1/date - date2/date / 24:0 to get a calendar day span. I personally don't ever remember having this need.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions