Skip to content

Zeller's Congruence Algorithm #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 5, 2019
Merged

Zeller's Congruence Algorithm #1095

merged 4 commits into from
Aug 5, 2019

Conversation

mrvnmchm
Copy link
Member

@mrvnmchm mrvnmchm commented Aug 3, 2019

Let me know of any other improvements I can make. 👍

Marvins-MBP:maths marvinmichum$ python3 zellers_congruence.py --help
usage: zellers_congruence.py [-h] date_input

Find out what day of the week nearly any date is or was. Enter date as a
string in the mm-dd-yyyy or mm/dd/yyyy format

positional arguments:
  date_input  Date as a string (mm-dd-yyyy or mm/dd/yyyy)

optional arguments:
  -h, --help  show this help message and exit
>>> import ZellersCongruence as z
>>> z.zeller('10/10/2018')
Your date 10/10/2018, is a Wednesday!
>>> z.zeller('04-23-1991')
Your date 04-23-1991, is a Tuesday!
>>> z.zeller('01-31-1976')
Your date 01-31-1976, is a Saturday!
Marvins-MBP:maths marvinmichum$ python3 zellers_congruence.py -v
Trying:
    zeller('01-31-2010')
Expecting:
    Your date 01-31-2010, is a Sunday!
ok
Trying:
    zeller('13-31-2010')
Expecting:
    Traceback (most recent call last):
    ...
    ValueError: Month must be between 1 - 12
ok
Trying:
    zeller('.2-31-2010')
Expecting:
    Traceback (most recent call last):
    ...
    ValueError: invalid literal for int() with base 10: '.2'
ok
Trying:
    zeller('01-33-2010')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Date must be between 1 - 31
ok
Trying:
    zeller('01-.4-2010')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: invalid literal for int() with base 10: '.4'
ok
Trying:
    zeller('01-31*2010')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Date seperator must be '-' or '/'
ok
Trying:
    zeller('01^31-2010')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Date seperator must be '-' or '/'
ok
Trying:
    zeller('01-31-8999')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Year out of range. There has to be some sort of limit...right?
ok
Trying:
    zeller()
Expecting:
    Traceback (most recent call last):
        ...
    TypeError: zeller() missing 1 required positional argument: 'date_input'
ok
Trying:
    zeller('')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Must be 10 characters long
ok
Trying:
    zeller('01-31-19082939')
Expecting:
    Traceback (most recent call last):
        ...
    ValueError: Must be 10 characters long
ok
1 items had no tests:
    __main__
1 items passed all tests:
  11 tests in __main__.zeller
11 tests in 2 items.
11 passed and 0 failed.
Test passed.

@cclauss
Copy link
Member

cclauss commented Aug 3, 2019

@mrvnmchm
Copy link
Member Author

mrvnmchm commented Aug 3, 2019

Removed unused import.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

This is a great piece of work. I approve it in its current state.
Please consider adding one or more tests to compare zeller()'s results against the Python standard library results:

>>> from datetime import datetime
>>> f"{datetime(2019, 8, 4):%A}"

Just FYI: Dates are a pain in all programming languages but these two libraries help...
https://arrow.readthedocs.io
https://www.kennethreitz.org/essays/introducing-maya-datetimes-for-humans

@mrvnmchm
Copy link
Member Author

mrvnmchm commented Aug 4, 2019

Updated to add suggestions, and to fix the issue with TravisCI and the Dict annotation.

@mrvnmchm mrvnmchm merged commit bdbe682 into TheAlgorithms:master Aug 5, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* doctest updates

* remove unused math import

* cleanup (suggestions)

* cleanup - Dict fix (TravisCI error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants