webchanges icon indicating copy to clipboard operation
webchanges copied to clipboard

[FEATURE] Support human-readable dates for database rollbacks

Open Markus00000 opened this issue 10 months ago • 1 comments

Is your feature request related to a problem? Please describe.

--rollback-database uses Unix timestamps, which can be inconvenient to obtain and are hard to comprehend for humans.

Describe the solution you'd like.

--rollback-database could support human-readable dates (e.g. in ISO format):

>>> import datetime
>>> d = datetime.datetime.fromisoformat('2024-04-23T14:26:40+02:00')
>>> d.replace(tzinfo=datetime.timezone.utc).timestamp()

Or using dateutil (examples):

>>> from dateutil import parser
>>> d = parser.parse('2024-04-23T14:39:38 CEST')
>>> d.replace(tzinfo=datetime.timezone.utc).timestamp()

dateutil accepts many inputs and is already installed as a dependency on my system for several applications. However, I am skeptical that an additional dependency is warranted considering how rarely most users will roll back their database. I would be happy with just datetime.datetime.fromisoformat.

In short:

--rollback-database ISO_DATE
--rollback-database TIMESTAMP

Markus00000 avatar Apr 23 '24 13:04 Markus00000

Makes sense, thanks for taking the time to make the suggestion!

Can structure it so that dateutil is used unless it's not found on the system, in which case it it falls back to using datetime (so there's no formal dependency on dateutil.

mborsetti avatar Apr 25 '24 05:04 mborsetti

@Markus00000 I just implemented a stealth version of this in v3.24, just released, but had no time for unit testing or documentation. Can you give it a try and see if it works for you?

mborsetti avatar Jun 06 '24 04:06 mborsetti

Date only, time only, date and time… everything was parsed as expected. So much more convenient than timestamps.

Showing the exact roll back date before rolling back is excellent, too.

Well done!

Markus00000 avatar Jun 06 '24 19:06 Markus00000

Thanks, and thanks for testing. Officially rolled out in v3.24.1.

mborsetti avatar Jun 14 '24 17:06 mborsetti