colombia-utils 0.1.0__tar.gz
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.
- colombia_utils-0.1.0/.gitattributes +1 -0
- colombia_utils-0.1.0/.github/workflows/ci.yml +19 -0
- colombia_utils-0.1.0/.gitignore +9 -0
- colombia_utils-0.1.0/CONTRIBUTING.md +19 -0
- colombia_utils-0.1.0/LICENSE +21 -0
- colombia_utils-0.1.0/PKG-INFO +84 -0
- colombia_utils-0.1.0/README.es.md +42 -0
- colombia_utils-0.1.0/README.md +68 -0
- colombia_utils-0.1.0/ROADMAP.md +31 -0
- colombia_utils-0.1.0/pyproject.toml +26 -0
- colombia_utils-0.1.0/src/colombia_utils/__init__.py +6 -0
- colombia_utils-0.1.0/src/colombia_utils/dates.py +91 -0
- colombia_utils-0.1.0/src/colombia_utils/nit.py +18 -0
- colombia_utils-0.1.0/tests/test_dates.py +71 -0
- colombia_utils-0.1.0/tests/test_nit.py +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python-version: ["3.10", "3.12", "3.14"]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: ${{ matrix.python-version }}
|
|
18
|
+
- run: pip install . pytest
|
|
19
|
+
- run: pytest
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Bug reports, ideas and pull requests are welcome, in English or Spanish.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -e . pytest
|
|
9
|
+
pytest
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Pull requests
|
|
13
|
+
|
|
14
|
+
- One feature or fix per pull request, with tests.
|
|
15
|
+
- No runtime dependencies: the library uses only the standard library.
|
|
16
|
+
- For dates and official rules (holidays, DIAN, DANE), link the source you used in the pull request.
|
|
17
|
+
- Use public or made-up data in tests: never real personal IDs or phone numbers.
|
|
18
|
+
|
|
19
|
+
Planned work is in [ROADMAP.md](ROADMAP.md) and the open issues.
|
|
@@ -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.
|
|
@@ -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
|
+
[](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,42 @@
|
|
|
1
|
+
# colombia-utils
|
|
2
|
+
|
|
3
|
+
[English](README.md) · **Español**
|
|
4
|
+
|
|
5
|
+
Utilidades pequeñas en Python, sin dependencias, para lo que toda aplicación colombiana termina necesitando: **festivos, días hábiles y dígito de verificación del NIT**.
|
|
6
|
+
|
|
7
|
+
Para quien desarrolla software de facturación, agendamiento, nómina o comercio electrónico en Colombia y está cansado de escribir a mano los festivos del próximo año o copiar la fórmula del dígito de verificación de un foro.
|
|
8
|
+
|
|
9
|
+
## Qué hace
|
|
10
|
+
|
|
11
|
+
- **Festivos de cualquier año desde 1984**, calculados según la ley y no copiados de una lista: fechas fijas, los que se corren al lunes por la Ley 51 de 1983 (Ley Emiliani) y los que dependen de la Semana Santa.
|
|
12
|
+
- **Días hábiles**: `is_business_day()` y `business_days(inicio, fin)` (lunes a viernes, sin festivos).
|
|
13
|
+
- **Dígito de verificación del NIT** con los pesos oficiales de la DIAN.
|
|
14
|
+
- Solo usa la biblioteca estándar, Python 3.10+, con pruebas.
|
|
15
|
+
|
|
16
|
+
## Instalación
|
|
17
|
+
|
|
18
|
+
Todavía no está en PyPI (mira el [roadmap](ROADMAP.md)). Se instala desde GitHub:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install git+https://github.com/kilianvega-dev/colombia-utils
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Uso
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from datetime import date
|
|
28
|
+
from colombia_utils import holidays, is_holiday, business_days, nit_check_digit
|
|
29
|
+
|
|
30
|
+
holidays(2027)[:3]
|
|
31
|
+
# [(date(2027, 1, 1), 'Año Nuevo'), (date(2027, 1, 11), 'Reyes Magos'), (date(2027, 3, 22), 'San José')]
|
|
32
|
+
|
|
33
|
+
is_holiday(date(2027, 1, 11)) # True: Reyes Magos pasa al lunes
|
|
34
|
+
business_days(date(2027, 3, 1), date(2027, 3, 31)) # 20: cuenta ambos extremos
|
|
35
|
+
nit_check_digit("800.197.268") # 4
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Las funciones tienen nombres en inglés y los festivos vienen con su nombre en español. La tabla completa de funciones está en el [README en inglés](README.md#usage).
|
|
39
|
+
|
|
40
|
+
## Licencia
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# colombia-utils
|
|
2
|
+
|
|
3
|
+
[](https://github.com/kilianvega-dev/colombia-utils/actions/workflows/ci.yml) · **English** · [Español](README.es.md)
|
|
4
|
+
|
|
5
|
+
Small, dependency-free Python helpers for things every Colombian app ends up needing: **public holidays, business days and NIT check digits**.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **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.
|
|
12
|
+
- **Business days**: `is_business_day()` and `business_days(start, end)` (Monday to Friday, skipping holidays).
|
|
13
|
+
- **NIT check digit** (dígito de verificación) with the official DIAN weights.
|
|
14
|
+
- Pure standard library, Python 3.10+, fully tested.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
Not on PyPI yet (see the [roadmap](ROADMAP.md)). Install from GitHub:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install git+https://github.com/kilianvega-dev/colombia-utils
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from datetime import date
|
|
28
|
+
from colombia_utils import holidays, is_holiday, business_days, nit_check_digit
|
|
29
|
+
|
|
30
|
+
holidays(2027)[:3]
|
|
31
|
+
# [(date(2027, 1, 1), 'Año Nuevo'), (date(2027, 1, 11), 'Reyes Magos'), (date(2027, 3, 22), 'San José')]
|
|
32
|
+
|
|
33
|
+
is_holiday(date(2027, 1, 11)) # True: Reyes Magos moved to Monday
|
|
34
|
+
business_days(date(2027, 3, 1), date(2027, 3, 31)) # 20: both ends included
|
|
35
|
+
nit_check_digit("800.197.268") # 4
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| Function | Returns |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `holidays(year)` | Sorted list of `(date, name)`. Two holidays can share a date (June 30, 2025). Raises `ValueError` before 1984. |
|
|
41
|
+
| `is_holiday(d)` | `True` if `d` is a public holiday. |
|
|
42
|
+
| `is_business_day(d)` | `True` for Monday to Friday that is not a holiday. |
|
|
43
|
+
| `business_days(start, end)` | Business days from `start` to `end`, both included. |
|
|
44
|
+
| `easter(year)` | Easter Sunday (Gregorian). |
|
|
45
|
+
| `nit_check_digit(nit)` | Check digit of a NIT given without it. Accepts dots and spaces; rejects anything else. |
|
|
46
|
+
|
|
47
|
+
## How holidays are computed
|
|
48
|
+
|
|
49
|
+
| Rule | Holidays |
|
|
50
|
+
|---|---|
|
|
51
|
+
| Fixed date | Año Nuevo, Día del Trabajo, Independencia (Jul 20), Batalla de Boyacá (Aug 7), Inmaculada Concepción, Navidad |
|
|
52
|
+
| 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 |
|
|
53
|
+
| Relative to Easter | Jueves and Viernes Santo; Ascensión, Corpus Christi and Sagrado Corazón (already on Monday) |
|
|
54
|
+
|
|
55
|
+
The tests check the result against the official 2025 and 2026 calendars.
|
|
56
|
+
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -e . pytest
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Planned work (validators, peso formatting, DANE codes, CLI, PyPI release) is in [ROADMAP.md](ROADMAP.md).
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
Goal: one small, trustworthy library for the Colombian rules that apps keep re-implementing. Each item is tracked as an issue; estimates are rough.
|
|
4
|
+
|
|
5
|
+
| # | Item | Type | Estimate |
|
|
6
|
+
|---|---|---|---|
|
|
7
|
+
| [#1](https://github.com/kilianvega-dev/colombia-utils/issues/1) | `add_business_days(d, n)` for legal and delivery deadlines | feature | ~2 h |
|
|
8
|
+
| [#2](https://github.com/kilianvega-dev/colombia-utils/issues/2) | `is_valid_nit("800197268-4")` and NIT formatting | feature | ~2 h |
|
|
9
|
+
| [#3](https://github.com/kilianvega-dev/colombia-utils/issues/3) | Validate and normalize Colombian phone numbers (mobile and 60X landlines) to E.164 | feature | ~3 h |
|
|
10
|
+
| [#4](https://github.com/kilianvega-dev/colombia-utils/issues/4) | `format_cop(1234567)` → `$1.234.567` without depending on the system locale | feature | ~1.5 h |
|
|
11
|
+
| [#5](https://github.com/kilianvega-dev/colombia-utils/issues/5) | Amounts in Spanish words for invoices ("un millón doscientos mil pesos") | feature | ~4 h |
|
|
12
|
+
| [#6](https://github.com/kilianvega-dev/colombia-utils/issues/6) | DANE departments and municipalities with code lookup | feature | ~4 h |
|
|
13
|
+
| [#7](https://github.com/kilianvega-dev/colombia-utils/issues/7) | Command line: `python -m colombia_utils festivos 2027`, `nit 800197268` | feature | ~3 h |
|
|
14
|
+
| [#8](https://github.com/kilianvega-dev/colombia-utils/issues/8) | Export holidays as an iCalendar (.ics) file | feature | ~2 h |
|
|
15
|
+
| [#9](https://github.com/kilianvega-dev/colombia-utils/issues/9) | Test holidays against official calendars for more years | test | ~2 h |
|
|
16
|
+
| [#10](https://github.com/kilianvega-dev/colombia-utils/issues/10) | Publish to PyPI from GitHub Actions, add type information (`py.typed`) | release | ~2 h |
|
|
17
|
+
| [#11](https://github.com/kilianvega-dev/colombia-utils/issues/11) | Usage examples tested with doctest and a short guide in Spanish | docs | ~2 h |
|
|
18
|
+
|
|
19
|
+
**Total: about 27 hours.**
|
|
20
|
+
|
|
21
|
+
## Suggested order
|
|
22
|
+
|
|
23
|
+
1. **Trust**: #9 (more official calendars) and #11 (tested examples).
|
|
24
|
+
2. **Most requested helpers**: #1, #2, #4.
|
|
25
|
+
3. **Bigger features**: #3, #5, #6, #8.
|
|
26
|
+
4. **Reach**: #7 and #10.
|
|
27
|
+
|
|
28
|
+
## Out of scope
|
|
29
|
+
|
|
30
|
+
- Storing or looking up real people's data (for example, querying the DIAN or the Registraduría).
|
|
31
|
+
- Runtime dependencies.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "colombia-utils"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Colombian holidays, business days and NIT check digits. Zero dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Kilian Vega" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
keywords = ["colombia", "holidays", "festivos", "business days", "nit", "dian"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Natural Language :: Spanish",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Repository = "https://github.com/kilianvega-dev/colombia-utils"
|
|
23
|
+
Issues = "https://github.com/kilianvega-dev/colombia-utils/issues"
|
|
24
|
+
|
|
25
|
+
[dependency-groups]
|
|
26
|
+
dev = ["pytest>=8"]
|
|
@@ -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))
|
|
@@ -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,71 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from colombia_utils import business_days, easter, holidays, is_business_day, is_holiday
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_easter_sunday_known_years():
|
|
9
|
+
assert easter(2024) == date(2024, 3, 31)
|
|
10
|
+
assert easter(2025) == date(2025, 4, 20)
|
|
11
|
+
assert easter(2026) == date(2026, 4, 5)
|
|
12
|
+
assert easter(2038) == date(2038, 4, 25) # latest possible date
|
|
13
|
+
assert easter(2285) == date(2285, 3, 22) # earliest possible date
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_holidays_2026_match_official_calendar():
|
|
17
|
+
# Official 2026 calendar: Emiliani holidays moved to Monday, Easter on April 5
|
|
18
|
+
assert [d for d, _ in holidays(2026)] == [
|
|
19
|
+
date(2026, 1, 1), date(2026, 1, 12), date(2026, 3, 23), date(2026, 4, 2),
|
|
20
|
+
date(2026, 4, 3), date(2026, 5, 1), date(2026, 5, 18), date(2026, 6, 8),
|
|
21
|
+
date(2026, 6, 15), date(2026, 6, 29), date(2026, 7, 20), date(2026, 8, 7),
|
|
22
|
+
date(2026, 8, 17), date(2026, 10, 12), date(2026, 11, 2), date(2026, 11, 16),
|
|
23
|
+
date(2026, 12, 8), date(2026, 12, 25),
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_holidays_have_spanish_names():
|
|
28
|
+
names = dict(holidays(2026))
|
|
29
|
+
assert names[date(2026, 10, 12)] == "Día de la Raza"
|
|
30
|
+
assert names[date(2026, 4, 3)] == "Viernes Santo"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_two_holidays_can_fall_on_the_same_monday():
|
|
34
|
+
# 2025: Sagrado Corazón and San Pedro y San Pablo were both moved to June 30
|
|
35
|
+
same_day = [name for d, name in holidays(2025) if d == date(2025, 6, 30)]
|
|
36
|
+
assert same_day == ["Sagrado Corazón", "San Pedro y San Pablo"]
|
|
37
|
+
assert len(holidays(2025)) == 18
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_holidays_before_ley_emiliani_are_rejected():
|
|
41
|
+
with pytest.raises(ValueError):
|
|
42
|
+
holidays(1983)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_is_holiday():
|
|
46
|
+
assert is_holiday(date(2026, 10, 12))
|
|
47
|
+
assert not is_holiday(date(2026, 10, 13))
|
|
48
|
+
assert not is_holiday(date(2026, 4, 5)) # Easter Sunday itself is not a holiday
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_is_business_day_excludes_weekends_and_holidays():
|
|
52
|
+
assert is_business_day(date(2026, 10, 13)) # Tuesday
|
|
53
|
+
assert not is_business_day(date(2026, 10, 12)) # Monday holiday
|
|
54
|
+
assert not is_business_day(date(2026, 10, 17)) # Saturday
|
|
55
|
+
assert not is_business_day(date(2026, 10, 18)) # Sunday
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_business_days_counts_both_ends():
|
|
59
|
+
# October 2026: 22 weekdays minus Día de la Raza
|
|
60
|
+
assert business_days(date(2026, 10, 1), date(2026, 10, 31)) == 21
|
|
61
|
+
assert business_days(date(2026, 10, 13), date(2026, 10, 13)) == 1
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_business_days_across_years():
|
|
65
|
+
# Dec 24 2026 (Thu) to Jan 4 2027 (Mon): Dec 24, 28, 29, 30, 31 and Jan 4
|
|
66
|
+
assert business_days(date(2026, 12, 24), date(2027, 1, 4)) == 6
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_business_days_rejects_reversed_range():
|
|
70
|
+
with pytest.raises(ValueError):
|
|
71
|
+
business_days(date(2026, 10, 31), date(2026, 10, 1))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from colombia_utils import nit_check_digit
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_check_digit_of_public_nits():
|
|
7
|
+
assert nit_check_digit("800197268") == 4 # DIAN
|
|
8
|
+
assert nit_check_digit("899999068") == 1 # Ecopetrol
|
|
9
|
+
assert nit_check_digit("890903938") == 8 # Bancolombia
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_check_digit_ignores_dots_and_spaces():
|
|
13
|
+
assert nit_check_digit("800.197.268") == 4
|
|
14
|
+
assert nit_check_digit(" 800 197 268 ") == 4
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_check_digit_accepts_int():
|
|
18
|
+
assert nit_check_digit(800197268) == 4
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_remainder_zero_or_one_is_used_as_is():
|
|
22
|
+
assert nit_check_digit("15") == 0 # 1*7 + 5*3 = 22, remainder 0
|
|
23
|
+
assert nit_check_digit("4") == 1 # 4*3 = 12, remainder 1
|
|
24
|
+
assert nit_check_digit("8") == 9 # 8*3 = 24, remainder 2 -> 11 - 2
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.parametrize("bad", ["", "abc", "800-197-268", "1234567890123456", "-5"])
|
|
28
|
+
def test_invalid_input_is_rejected(bad):
|
|
29
|
+
with pytest.raises(ValueError):
|
|
30
|
+
nit_check_digit(bad)
|