Skip to content

Commit e41ffcc

Browse files
author
Rodrigo Roldán
committed
docs: Update docs, add new examples
1 parent 3f1d623 commit e41ffcc

13 files changed

Lines changed: 1192 additions & 22 deletions

docs/source/changelog.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
All versions are documented in this file.
44

5+
## [1.2.0] - 2025-06-25
6+
- Added locale-aware `diff_for_humans` via the new `humanize` module.
7+
- Introduced `eones/locales/` package for language messages.
8+
- Exposed `diff_for_humans` on `Date` and `Eones` classes.
9+
- Documented language extensibility and added tests.
10+
- Added comparison helpers `Date.is_same_day`, `Date.is_before`, `Date.is_after` and `Date.days_until`
11+
- Added `Date.as_local` property and renamed timezone conversion method to `as_zone`
12+
- Integration tests now skip if Django or SQLAlchemy are not installed
13+
14+
---
15+
16+
## [1.1.0] - 2025-06-13
17+
- Updated `pyproject.toml` to `1.1.0`.
18+
- Updated `README.md` to `1.1.0`.
19+
- Added Docstrings to all methods and classes in the source code and tests.
20+
- Added tests for all methods and classes.
21+
- Reached `99%` coverage for tests.
22+
- Added methods for handling ranges and periods.
23+
- Fixed bugs in comparison methods.
24+
- Added bugs for later fixes.
25+
526
---
627

728
## [1.0.0] - 2025-05-19

docs/source/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
exclude_patterns = []
1919

2020
html_baseurl = "https://roldriel.github.io/eones/"
21-
html_extra_path = ["extra"]
2221
html_theme = "alabaster"
2322
html_static_path = ["_static"]
2423
autodoc_mock_imports = ["django", "sqlalchemy"]
2524
html_theme_options = {
2625
"canonical_url": "https://roldriel.github.io/eones/",
27-
"navigation_depth": 4,
2826
}
2927
html_context = {
3028
"display_github": True,

docs/source/eones.core.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ eones.core.delta module
2525
:show-inheritance:
2626
:undoc-members:
2727

28+
eones.core.delta\_calendar module
29+
---------------------------------
30+
31+
.. automodule:: eones.core.delta_calendar
32+
:members:
33+
:show-inheritance:
34+
:undoc-members:
35+
36+
eones.core.delta\_duration module
37+
---------------------------------
38+
39+
.. automodule:: eones.core.delta_duration
40+
:members:
41+
:show-inheritance:
42+
:undoc-members:
43+
2844
eones.core.parser module
2945
------------------------
3046

docs/source/eones.locales.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
eones.locales package
2+
=====================
3+
4+
.. automodule:: eones.locales
5+
:members:
6+
:show-inheritance:
7+
:undoc-members:
8+
9+
Submodules
10+
----------
11+
12+
eones.locales.en module
13+
-----------------------
14+
15+
.. automodule:: eones.locales.en
16+
:members:
17+
:show-inheritance:
18+
:undoc-members:
19+
20+
eones.locales.es module
21+
-----------------------
22+
23+
.. automodule:: eones.locales.es
24+
:members:
25+
:show-inheritance:
26+
:undoc-members:

docs/source/eones.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Subpackages
1414

1515
eones.core
1616
eones.integrations
17+
eones.locales
1718

1819
Submodules
1920
----------
@@ -42,6 +43,14 @@ eones.formats module
4243
:show-inheritance:
4344
:undoc-members:
4445

46+
eones.humanize module
47+
---------------------
48+
49+
.. automodule:: eones.humanize
50+
:members:
51+
:show-inheritance:
52+
:undoc-members:
53+
4554
eones.interface module
4655
----------------------
4756

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Advanced Usage of Eones
2+
3+
This file contains advanced examples of date and time manipulation with Eones.
4+
5+
## Advanced Date Manipulation
6+
7+
### Truncation and Rounding
8+
9+
```python
10+
date = Eones("2024-06-15 14:30:45")
11+
12+
# Truncate to the start of different units
13+
date.floor("day") # 2024-06-15 00:00:00
14+
date.floor("month") # 2024-06-01 00:00:00
15+
date.floor("year") # 2024-01-01 00:00:00
16+
date.floor("hour") # 2024-06-15 14:00:00
17+
18+
# Advance to the end of different units
19+
date.ceil("day") # 2024-06-15 23:59:59
20+
date.ceil("month") # 2024-06-30 23:59:59
21+
date.ceil("year") # 2024-12-31 23:59:59
22+
23+
# Round to the nearest unit
24+
date.round("hour") # Round to the nearest hour
25+
date.round("day") # Round to the nearest day
26+
```
27+
28+
### Start and End of Periods
29+
30+
```python
31+
date = Eones("2024-06-15 14:30:45")
32+
33+
# Go to the start of different periods
34+
date.start_of("day") # 2024-06-15 00:00:00
35+
date.start_of("week") # Monday of that week
36+
date.start_of("month") # 2024-06-01 00:00:00
37+
date.start_of("year") # 2024-01-01 00:00:00
38+
39+
# Go to the end of different periods
40+
date.end_of("day") # 2024-06-15 23:59:59
41+
date.end_of("week") # Sunday of that week
42+
date.end_of("month") # 2024-06-30 23:59:59
43+
date.end_of("year") # 2024-12-31 23:59:59
44+
```
45+
46+
### Component Replacement
47+
48+
```python
49+
date = Eones("2024-06-15 14:30:45")
50+
51+
# Change specific components
52+
date.replace(day=1) # Change to day 1 of the month
53+
date.replace(month=12) # Change to December
54+
date.replace(year=2025) # Change to 2025
55+
date.replace(hour=0, minute=0, second=0) # Midnight
56+
57+
print(date.format("%Y-%m-%d %H:%M:%S"))
58+
```
59+
60+
## Comparisons and Validations
61+
62+
### Date Comparisons
63+
64+
```python
65+
date1 = Eones("2024-01-01")
66+
date2 = Eones("2024-12-31")
67+
date3 = Eones("2024-06-15")
68+
69+
# Check if a date is between two others
70+
is_between = date3.is_between(date1, date2)
71+
print(is_between) # True
72+
73+
# Check if they are in the same week
74+
same_week = date1.is_same_week(date2)
75+
print(same_week) # False
76+
77+
# Check if they are in the same month/year
78+
same_month = date1.is_within(date3, check_month=True)
79+
same_year = date1.is_within(date3, check_month=False)
80+
```
81+
82+
### Next Weekdays
83+
84+
```python
85+
date = Eones("2024-06-15") # Assume it's Saturday
86+
87+
# Find the next Monday (0=Monday, 6=Sunday)
88+
next_monday = date.next_weekday(0)
89+
print(next_monday.format("%Y-%m-%d")) # Date of next Monday
90+
91+
# Next Friday
92+
next_friday = date.next_weekday(4)
93+
print(next_friday.format("%Y-%m-%d"))
94+
```
95+
96+
## Date Ranges
97+
98+
### Get period ranges
99+
100+
```python
101+
date = Eones("2024-06-15")
102+
103+
# Get ranges for different periods
104+
day_range = date.range("day") # (day_start, day_end)
105+
month_range = date.range("month") # (month_start, month_end)
106+
year_range = date.range("year") # (year_start, year_end)
107+
108+
# Ranges return datetime tuples
109+
start, end = month_range
110+
print(f"Month: from {start} to {end}")
111+
```
112+
113+
## Additional Methods of the Date Class
114+
115+
### Navigation by Weekdays
116+
117+
```python
118+
date = Eones("2024-06-15") # Assume it's Saturday
119+
120+
# Find the next specific weekday
121+
next_monday = date.next_weekday(0) # 0=Monday, 1=Tuesday, ..., 6=Sunday
122+
next_friday = date.next_weekday(4)
123+
124+
# Find the previous specific weekday
125+
previous_wednesday = date.previous_weekday(2)
126+
127+
print(next_monday.format("%Y-%m-%d")) # Date of next Monday
128+
print(previous_wednesday.format("%Y-%m-%d")) # Date of previous Wednesday
129+
```
130+
131+
### Dictionary Conversion
132+
133+
```python
134+
date = Eones("2024-06-15 14:30:45")
135+
136+
# Convert to dictionary with all components
137+
date_dict = date.to_dict()
138+
print(date_dict)
139+
# {
140+
# 'year': 2024,
141+
# 'month': 6,
142+
# 'day': 15,
143+
# 'hour': 14,
144+
# 'minute': 30,
145+
# 'second': 45,
146+
# 'microsecond': 0,
147+
# 'timezone': 'UTC'
148+
# }
149+
```
150+
151+
### Specific Period Ranges
152+
153+
```python
154+
date = Eones("2024-06-15")
155+
156+
# Get specific ranges using the Range class
157+
quarter_range = date.quarter_range() # Start and end of current quarter
158+
iso_week_range = date.week_range() # ISO week (Monday to Sunday)
159+
160+
# Ranges return datetime tuples
161+
quarter_start, quarter_end = quarter_range
162+
print(f"Quarter: {quarter_start} - {quarter_end}")
163+
```
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Basic Usage of Eones
2+
3+
This file contains basic examples to get started with the Eones library.
4+
5+
## Import
6+
7+
```python
8+
from eones import Eones
9+
```
10+
11+
## Creating Dates
12+
13+
### Different ways to create dates
14+
15+
```python
16+
# Current date
17+
current_date = Eones()
18+
19+
# From string (multiple formats supported)
20+
date1 = Eones("2024-12-25")
21+
date2 = Eones("25/12/2024")
22+
date3 = Eones("25-12-2024")
23+
date4 = Eones("2024-12-25 15:30:00")
24+
25+
# From dictionary
26+
date5 = Eones({"year": 2024, "month": 12, "day": 25, "hour": 15})
27+
28+
# From Python datetime
29+
from datetime import datetime
30+
date6 = Eones(datetime.now())
31+
32+
# With specific timezone
33+
madrid_date = Eones("2024-12-25", tz="Europe/Madrid")
34+
mexico_date = Eones("2024-12-25", tz="America/Mexico_City")
35+
```
36+
37+
## Date Formatting
38+
39+
### Different output formats
40+
41+
```python
42+
date = Eones("2024-12-25 15:30:00")
43+
44+
# Different output formats
45+
print(date.format("%Y-%m-%d")) # 2024-12-25
46+
print(date.format("%d/%m/%Y")) # 25/12/2024
47+
print(date.format("%d de %B de %Y")) # 25 de December de 2024
48+
print(date.format("%H:%M:%S")) # 15:30:00
49+
```
50+
51+
## Adding and Subtracting Time
52+
53+
### Adding time to a date
54+
55+
```python
56+
date = Eones("2024-01-15")
57+
58+
# Add time
59+
date.add(days=10) # Add 10 days
60+
date.add(months=2) # Add 2 months
61+
date.add(years=1, days=5) # Add 1 year and 5 days
62+
date.add(hours=3, minutes=30) # Add 3 hours and 30 minutes
63+
64+
print(date.format("%Y-%m-%d %H:%M")) # Result after additions
65+
```
66+
67+
## Differences Between Dates
68+
69+
### Calculate differences
70+
71+
```python
72+
date1 = Eones("2024-01-01")
73+
date2 = Eones("2024-12-31")
74+
75+
# Calculate difference
76+
difference = date2.difference(date1)
77+
print(difference) # Shows the difference in Delta format
78+
79+
# Difference in specific units
80+
days_difference = date2.difference(date1, unit="days")
81+
months_difference = date2.difference(date1, unit="months")
82+
83+
# Human-readable difference
84+
print(date2.diff_for_humans(date1)) # "11 months ago" (in English)
85+
print(date2.diff_for_humans(date1, locale="es")) # "hace 11 meses" (in Spanish)
86+
```
87+
88+
## Custom Parsing
89+
90+
### Using custom formats
91+
92+
```python
93+
# Use custom formats
94+
custom_formats = ["%d-%m-%Y", "%Y/%m/%d"]
95+
date = Eones("15-06-2024", formats=custom_formats)
96+
97+
# Add additional formats to defaults
98+
date = Eones("15-06-2024", additional_formats=["%d-%m-%Y"])
99+
```
100+
101+
## Localization
102+
103+
### Support for multiple languages
104+
105+
```python
106+
date1 = Eones("2024-01-01")
107+
date2 = Eones("2024-01-15")
108+
109+
# In English (default)
110+
print(date2.diff_for_humans(date1)) # "2 weeks ago"
111+
112+
# In Spanish
113+
print(date2.diff_for_humans(date1, locale="es")) # "hace 2 semanas"
114+
```

0 commit comments

Comments
 (0)