MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / zeller

Function zeller

maths/zellers_congruence.py:5–147  ·  view source on GitHub ↗

| Zellers Congruence Algorithm | Find the day of the week for nearly any Gregorian or Julian calendar date >>> zeller('01-31-2010') 'Your date 01-31-2010, is a Sunday!' Validate out of range month: >>> zeller('13-31-2010') Traceback (most recent call last): ..

(date_input: str)

Source from the content-addressed store, hash-verified

3
4
5def zeller(date_input: str) -> str:
6 """
7 | Zellers Congruence Algorithm
8 | Find the day of the week for nearly any Gregorian or Julian calendar date
9
10 >>> zeller('01-31-2010')
11 'Your date 01-31-2010, is a Sunday!'
12
13 Validate out of range month:
14
15 >>> zeller('13-31-2010')
16 Traceback (most recent call last):
17 ...
18 ValueError: Month must be between 1 - 12
19 >>> zeller('.2-31-2010')
20 Traceback (most recent call last):
21 ...
22 ValueError: invalid literal for int() with base 10: '.2'
23
24 Validate out of range date:
25
26 >>> zeller('01-33-2010')
27 Traceback (most recent call last):
28 ...
29 ValueError: Date must be between 1 - 31
30 >>> zeller('01-.4-2010')
31 Traceback (most recent call last):
32 ...
33 ValueError: invalid literal for int() with base 10: '.4'
34
35 Validate second separator:
36
37 >>> zeller('01-31*2010')
38 Traceback (most recent call last):
39 ...
40 ValueError: Date separator must be '-' or '/'
41
42 Validate first separator:
43
44 >>> zeller('01^31-2010')
45 Traceback (most recent call last):
46 ...
47 ValueError: Date separator must be '-' or '/'
48
49 Validate out of range year:
50
51 >>> zeller('01-31-8999')
52 Traceback (most recent call last):
53 ...
54 ValueError: Year out of range. There has to be some sort of limit...right?
55
56 Test null input:
57
58 >>> zeller()
59 Traceback (most recent call last):
60 ...
61 TypeError: zeller() missing 1 required positional argument: 'date_input'
62

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected