Skip to content

Fix failing duration conversion#449

Merged
SebastiaanZ merged 3 commits into
masterfrom
duration-converter-fix
Sep 23, 2019
Merged

Fix failing duration conversion#449
SebastiaanZ merged 3 commits into
masterfrom
duration-converter-fix

Conversation

@SebastiaanZ
Copy link
Copy Markdown
Contributor

The current ExpirationDate converter does not convert duration strings to datetime.datetime objects correctly. To remedy the problem, I've written a new Duration converter that uses regex matching to extract the relevant duration units and dateutil.relativedelta.relativedelta to compute a datetime.datetime that's the given duration in the future.

I've left the old ExpirationDate converter in place for now, since the new Duration converter may not be the most optimal method. However, given the importance of being able to convert durations for moderation tasks, I think it's better to implement the Duration converter now and rethink the approach later.

This PR closes #446

#446

The current ExpirationDate converter does not convert duration strings
to `datetime.datetime` objects correctly. To remedy the problem, I've
written a new Duration converter that uses regex matching to extract
the relevant duration units and `dateutil.relativedelta.relativedelta`
to compute a `datetime.datetime` that's the given duration in the
future.

I've left the old `ExpirationDate` converter in place for now, since
the new Duration converter may not be the most optimal method. However,
given the importance of being able to convert durations for moderation
tasks, I think it's better to implement Duration now and rethink the
approach later.

This commit closes #446
@SebastiaanZ SebastiaanZ requested review from MarkKoz and sco1 September 23, 2019 19:33
Comment thread bot/converters.py
Comment thread tests/test_converters.py
Comment thread tests/test_converters.py Outdated
#446

After review feedback and a discussion in the dev-core team, I've
changed a couple of things:

- Allow a space between amount and unit in the duration string;

- Allow a space between different units in the duration string;

- Remove the old ExpirationDate converter completely;

- Remove the dependency `dateparser` from the Pipfile;

- Update tests for the two types of optional spaces;

- Change the test for valid cases to a more readable format;

This PR closes #446
In this commit, I've restructured the Duration converter's docstring
to a more readable format: a bullet point list.
@SebastiaanZ SebastiaanZ added a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 0 - critical Needs to be addressed ASAP t: bug Something isn't working labels Sep 23, 2019
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why the space regex couldn't have been * but it's good enough.

Copy link
Copy Markdown
Contributor

@sco1 sco1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems rock solid

@SebastiaanZ SebastiaanZ merged commit f58c578 into master Sep 23, 2019
@SebastiaanZ SebastiaanZ deleted the duration-converter-fix branch September 23, 2019 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 0 - critical Needs to be addressed ASAP t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpirationDate Converter Not Correctly Parsing Duration Directives

3 participants