colombia-utils 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ """Colombian holidays, business days and NIT check digits."""
2
+
3
+ from .dates import business_days, easter, holidays, is_business_day, is_holiday
4
+ from .nit import nit_check_digit
5
+
6
+ __all__ = ["business_days", "easter", "holidays", "is_business_day", "is_holiday", "nit_check_digit"]
@@ -0,0 +1,91 @@
1
+ """Colombian public holidays (Ley 51 de 1983) and business days."""
2
+
3
+ from datetime import date, timedelta
4
+ from functools import lru_cache
5
+
6
+
7
+ def easter(year: int) -> date:
8
+ """Easter Sunday of the Gregorian calendar (anonymous Gregorian algorithm)."""
9
+ a = year % 19
10
+ b, c = divmod(year, 100)
11
+ d, e = divmod(b, 4)
12
+ f = (b + 8) // 25
13
+ g = (b - f + 1) // 3
14
+ h = (19 * a + b - d - g + 15) % 30
15
+ i, k = divmod(c, 4)
16
+ l = (32 + 2 * e + 2 * i - h - k) % 7
17
+ m = (a + 11 * h + 22 * l) // 451
18
+ month, day = divmod(h + l - 7 * m + 114, 31)
19
+ return date(year, month, day + 1)
20
+
21
+
22
+ # Holidays that always fall on their own date
23
+ _FIXED = [
24
+ (1, 1, "Año Nuevo"),
25
+ (5, 1, "Día del Trabajo"),
26
+ (7, 20, "Día de la Independencia"),
27
+ (8, 7, "Batalla de Boyacá"),
28
+ (12, 8, "Inmaculada Concepción"),
29
+ (12, 25, "Navidad"),
30
+ ]
31
+
32
+ # Ley 51 de 1983 ("Ley Emiliani"): moved to the following Monday
33
+ _MOVED = [
34
+ (1, 6, "Reyes Magos"),
35
+ (3, 19, "San José"),
36
+ (6, 29, "San Pedro y San Pablo"),
37
+ (8, 15, "Asunción de la Virgen"),
38
+ (10, 12, "Día de la Raza"),
39
+ (11, 1, "Todos los Santos"),
40
+ (11, 11, "Independencia de Cartagena"),
41
+ ]
42
+
43
+ # Days after Easter Sunday; the last three already land on the Monday the law moves them to
44
+ _FROM_EASTER = [
45
+ (-3, "Jueves Santo"),
46
+ (-2, "Viernes Santo"),
47
+ (43, "Ascensión del Señor"),
48
+ (64, "Corpus Christi"),
49
+ (71, "Sagrado Corazón"),
50
+ ]
51
+
52
+
53
+ def _next_monday(d: date) -> date:
54
+ return d + timedelta(days=-d.weekday() % 7)
55
+
56
+
57
+ def holidays(year: int) -> list[tuple[date, str]]:
58
+ """Colombian public holidays of ``year`` as sorted ``(date, name)`` pairs.
59
+
60
+ Two holidays can share a date (both are listed). Raises ``ValueError``
61
+ before 1984, when the current holiday law took effect.
62
+ """
63
+ if year < 1984:
64
+ raise ValueError(f"holidays are only defined from 1984 (Ley 51 de 1983), got {year}")
65
+ sunday = easter(year)
66
+ days = [(date(year, m, d), name) for m, d, name in _FIXED]
67
+ days += [(_next_monday(date(year, m, d)), name) for m, d, name in _MOVED]
68
+ days += [(sunday + timedelta(days=offset), name) for offset, name in _FROM_EASTER]
69
+ return sorted(days)
70
+
71
+
72
+ @lru_cache(maxsize=None)
73
+ def _holiday_dates(year: int) -> frozenset[date]:
74
+ return frozenset(d for d, _ in holidays(year))
75
+
76
+
77
+ def is_holiday(d: date) -> bool:
78
+ """True if ``d`` is a Colombian public holiday."""
79
+ return d in _holiday_dates(d.year)
80
+
81
+
82
+ def is_business_day(d: date) -> bool:
83
+ """True if ``d`` is a Monday to Friday that is not a public holiday."""
84
+ return d.weekday() < 5 and not is_holiday(d)
85
+
86
+
87
+ def business_days(start: date, end: date) -> int:
88
+ """Number of business days from ``start`` to ``end``, both included."""
89
+ if end < start:
90
+ raise ValueError(f"end ({end}) is before start ({start})")
91
+ return sum(is_business_day(start + timedelta(days=i)) for i in range((end - start).days + 1))
colombia_utils/nit.py ADDED
@@ -0,0 +1,18 @@
1
+ """NIT (Número de Identificación Tributaria) check digit, as defined by the DIAN."""
2
+
3
+ # DIAN weights, applied from the rightmost digit
4
+ _WEIGHTS = (3, 7, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71)
5
+
6
+
7
+ def nit_check_digit(nit: str | int) -> int:
8
+ """Check digit (dígito de verificación) of a NIT without its check digit.
9
+
10
+ Dots and spaces are ignored. Raises ``ValueError`` for anything that is
11
+ not 1 to 15 digits, including a hyphen, which usually means the check
12
+ digit is already attached.
13
+ """
14
+ digits = str(nit).replace(".", "").replace(" ", "")
15
+ if not (digits.isdigit() and digits.isascii() and len(digits) <= len(_WEIGHTS)):
16
+ raise ValueError(f"a NIT must be 1 to {len(_WEIGHTS)} digits, got {nit!r}")
17
+ remainder = sum(int(c) * w for c, w in zip(reversed(digits), _WEIGHTS)) % 11
18
+ return remainder if remainder < 2 else 11 - remainder
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.5
2
+ Name: colombia-utils
3
+ Version: 0.1.0
4
+ Summary: Colombian holidays, business days and NIT check digits. Zero dependencies.
5
+ Project-URL: Repository, https://github.com/kilianvega-dev/colombia-utils
6
+ Project-URL: Issues, https://github.com/kilianvega-dev/colombia-utils/issues
7
+ Author: Kilian Vega
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: business days,colombia,dian,festivos,holidays,nit
11
+ Classifier: Natural Language :: Spanish
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # colombia-utils
18
+
19
+ [![CI](https://github.com/kilianvega-dev/colombia-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/kilianvega-dev/colombia-utils/actions/workflows/ci.yml) · **English** · [Español](README.es.md)
20
+
21
+ Small, dependency-free Python helpers for things every Colombian app ends up needing: **public holidays, business days and NIT check digits**.
22
+
23
+ For developers building invoicing, scheduling, payroll or e-commerce software for Colombia who are tired of hard-coding next year's holidays or copying the DIAN check-digit formula from a forum.
24
+
25
+ ## Features
26
+
27
+ - **Public holidays for any year from 1984**, computed from the law instead of a hard-coded list: fixed dates, holidays moved to Monday by Ley 51 de 1983 ("Ley Emiliani") and the ones that depend on Easter. Names in Spanish.
28
+ - **Business days**: `is_business_day()` and `business_days(start, end)` (Monday to Friday, skipping holidays).
29
+ - **NIT check digit** (dígito de verificación) with the official DIAN weights.
30
+ - Pure standard library, Python 3.10+, fully tested.
31
+
32
+ ## Install
33
+
34
+ Not on PyPI yet (see the [roadmap](ROADMAP.md)). Install from GitHub:
35
+
36
+ ```bash
37
+ pip install git+https://github.com/kilianvega-dev/colombia-utils
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```python
43
+ from datetime import date
44
+ from colombia_utils import holidays, is_holiday, business_days, nit_check_digit
45
+
46
+ holidays(2027)[:3]
47
+ # [(date(2027, 1, 1), 'Año Nuevo'), (date(2027, 1, 11), 'Reyes Magos'), (date(2027, 3, 22), 'San José')]
48
+
49
+ is_holiday(date(2027, 1, 11)) # True: Reyes Magos moved to Monday
50
+ business_days(date(2027, 3, 1), date(2027, 3, 31)) # 20: both ends included
51
+ nit_check_digit("800.197.268") # 4
52
+ ```
53
+
54
+ | Function | Returns |
55
+ |---|---|
56
+ | `holidays(year)` | Sorted list of `(date, name)`. Two holidays can share a date (June 30, 2025). Raises `ValueError` before 1984. |
57
+ | `is_holiday(d)` | `True` if `d` is a public holiday. |
58
+ | `is_business_day(d)` | `True` for Monday to Friday that is not a holiday. |
59
+ | `business_days(start, end)` | Business days from `start` to `end`, both included. |
60
+ | `easter(year)` | Easter Sunday (Gregorian). |
61
+ | `nit_check_digit(nit)` | Check digit of a NIT given without it. Accepts dots and spaces; rejects anything else. |
62
+
63
+ ## How holidays are computed
64
+
65
+ | Rule | Holidays |
66
+ |---|---|
67
+ | Fixed date | Año Nuevo, Día del Trabajo, Independencia (Jul 20), Batalla de Boyacá (Aug 7), Inmaculada Concepción, Navidad |
68
+ | Moved to the next Monday (Ley 51 de 1983) | Reyes Magos, San José, San Pedro y San Pablo, Asunción, Día de la Raza, Todos los Santos, Independencia de Cartagena |
69
+ | Relative to Easter | Jueves and Viernes Santo; Ascensión, Corpus Christi and Sagrado Corazón (already on Monday) |
70
+
71
+ The tests check the result against the official 2025 and 2026 calendars.
72
+
73
+ ## Development
74
+
75
+ ```bash
76
+ pip install -e . pytest
77
+ pytest
78
+ ```
79
+
80
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Planned work (validators, peso formatting, DANE codes, CLI, PyPI release) is in [ROADMAP.md](ROADMAP.md).
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,7 @@
1
+ colombia_utils/__init__.py,sha256=MwyLlRUl0ZU7T1wlF2a8Oy9g0b5sZ7MCQEEH6Epdygg,279
2
+ colombia_utils/dates.py,sha256=-JmcQ-Y0BNqXFjuLDRO-QQE6bhWBEyuANwZ72z0f-ac,2922
3
+ colombia_utils/nit.py,sha256=pJgvvrCGxRo3NoL8y9Wt0Gz2BtJ384BmpYPrpoRKbYk,887
4
+ colombia_utils-0.1.0.dist-info/METADATA,sha256=VnwXmjxARanNpijHvKATOprDbW2a6y39Y0G8O5kd4VE,3653
5
+ colombia_utils-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ colombia_utils-0.1.0.dist-info/licenses/LICENSE,sha256=GiE0uH4gBfx1AoxNFNX4B8qWmJ1Hdxu21XAulTlzqbE,1068
7
+ colombia_utils-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kilian Vega
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.