Kosmorro / kosmorro

A program to calculate your ephemerides.
https://kosmorro.space
GNU Affero General Public License v3.0
60 stars 7 forks source link

Add support for relative dates in the `--date` argument #74

Closed Deuchnord closed 4 years ago

Deuchnord commented 4 years ago

Is your feature request related to a problem? Please describe. Since version 0.7, the --day, --month and --year arguments have been removed in the favor of a single, more simple --date one. But as a side-effect, calculating the ephemerides of the next days is now much more painful, because we now need to give the entire date: before, we could give the --day only for instance, and the month and year were automatically guessed to the current ones.

Describe the solution you'd like Add the capacity for the --date argument to understand relative dates. The solution I imagine is something inspired from PHP's DateInterval constructor, but in a more user-friendly style.

The format would follow the following regular expression:

^([+-])(([0-9]+)y)?[ ]?(([0-9]+)m)?[ ]?(([0-9]+)d)?$

Examples of valid intervals:

Describe alternatives you've considered Currently, the only possible alternative is to give the entire date in the YYYY-MM-DD format.

Brainface1 commented 4 years ago

I have implemented the basics of this (https://github.com/Brainface1/kosmorro) however i have two questions:

  1. I added a new dependency (dateutil for its relativedelta implementation) is this ok?
  2. argparse doesnt allow leading dashes as arguments, because it recognizes them as flags. Does someone have a suggestion for working around this issue?
Deuchnord commented 4 years ago

Hello, thanks for your work! Feel free to open a PR when you want :)

I added a new dependency (dateutil for its relativedelta implementation) is this ok?

I didn't know this library, if you think it it should be used, feel free to add it :) Don't forget to use pipenv install <library name> to update the Pipfile to ensure the lock file is up-to-date.

argparse doesnt allow leading dashes as arguments, because it recognizes them as flags. Does someone have a suggestion for working around this issue?

Can reproduce this too… According to this answer on StackOverflow, you can use either the --date=<offset> or the -d=<offset> format instead :)