PeriodicalDates.jl icon indicating copy to clipboard operation
PeriodicalDates.jl copied to clipboard

string literal macros

Open FuZhiyu opened this issue 2 years ago • 3 comments

I got lazy again and found the construction of a single quarterly date is a bit tedious (QuarterlyDate(2020, 1)). Do you consider adding string literal macros to the package? Here is my idea:

macro yq_str(ymstr)
    return :(QuarterlyDate($ymstr))
end

macro ym_str(ymstr)
    return :(MonthlyDate($ymstr))
end

so a QuarterlyDate(2020, 3) can be simply constructed as yq"2020-Q3".

FuZhiyu avatar Feb 07 '23 17:02 FuZhiyu

Maybe. Do these types of string literal macros to construct dates exist anywhere else?

matthieugomez avatar Feb 07 '23 17:02 matthieugomez

Note that you can already do QuarterlyDate("2020-Q3")

matthieugomez avatar Feb 07 '23 17:02 matthieugomez

Maybe. Do these types of string literal macros to construct dates exist anywhere else?

No. But I guess that's because Date is relatively easy to type while QuarterlyDate is pretty tedious.

Your call. I can also simply put it into my own header file.

FuZhiyu avatar Feb 07 '23 19:02 FuZhiyu