psss / did

What did you do last week, month, year?
https://did.readthedocs.io/
GNU General Public License v2.0
247 stars 105 forks source link

Add last friday command #197

Closed lzap closed 5 years ago

lzap commented 5 years ago

I report on a daily basis and I miss ability to report last Friday. This should do it, also support next Friday which does not make sense, but it's good to be consistent. Not a pythonist, so take care reviewing.

I wanted to add a more generic "last business day" command but it turns out that it's tough to do business days in plain Python and I do not want to add another dependency because of this. If you want the patch to be Israel-friendly, then I can add also "last sunday" or maybe all the days but that could be little bit noisy.

AloisMahdal commented 5 years ago

BTW, you could hack around it by something like:

did --since `date -d 'last friday' +%Y-%m-%d` --until `date -d 'last friday' +%Y-%m-%d`

or

did_1day() {
    #
    # Report activity for day $1 (in format accepted by date(1) -d)
    #
    local expr=("$@")
    local day
    day=$(date -d "${expr[*]}" +%Y-%m-%d) || {
        echo "could not convert date: '${expr[*]}'" >&2
        return 3
    }
    did --since "$day" --until "$day"
}

and then just call

did_1day last friday

..in the end it would be much more poweful than adding every expression as extra command, since it can do many other tricks.

Or, maybe did could have a way to convert the expression internally?

lzap commented 5 years ago

Hmm I did not see "NameError: global name 'FR' is not defined" locally, this is probably defined in the delta module. Anyway, let me know if you want this patch otherwise I'd just drop it given the workaround (nice thanks).

psss commented 5 years ago

Thanks for the patch. Looks fine. Going to merge after a couple of adjustments in 06bae06. We can extend date selection to be more generic in the future. The last friday seems that it could be a relatively common use case so it's worth to include it now.