python-intl 0.3.1__tar.gz → 0.4.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.
- {python_intl-0.3.1 → python_intl-0.4.0}/PKG-INFO +12 -5
- {python_intl-0.3.1 → python_intl-0.4.0}/README.md +11 -4
- {python_intl-0.3.1 → python_intl-0.4.0}/pyproject.toml +1 -1
- {python_intl-0.3.1 → python_intl-0.4.0}/pyproject.toml.orig +1 -1
- {python_intl-0.3.1 → python_intl-0.4.0}/python_intl/datetimeformat.py +9 -0
- {python_intl-0.3.1 → python_intl-0.4.0}/LICENSE +0 -0
- {python_intl-0.3.1 → python_intl-0.4.0}/python_intl/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-intl
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python implementation of the Intl JavaScript API
|
|
5
5
|
Author: David Danier
|
|
6
6
|
Author-email: David Danier <david.danier@gmail.com>
|
|
@@ -21,6 +21,11 @@ the "same" code works on JavaScript and Python, with similar results.
|
|
|
21
21
|
**Status:** This is very much work in progress. Currently only `Intl.DateTimeFormat`
|
|
22
22
|
exists and this also is not complete yet.
|
|
23
23
|
|
|
24
|
+
**Note:** There are a lot of tests running the Python implementation against the
|
|
25
|
+
JavaScript one and comparing the results. In general things should be pretty
|
|
26
|
+
stable there. Still there are some cases with known differences. Also note
|
|
27
|
+
that results depend on the ICU version you have installed on your machine.
|
|
28
|
+
|
|
24
29
|
## General notes about the Python adaption
|
|
25
30
|
|
|
26
31
|
All names will be using the Python style rules. This means instead of
|
|
@@ -55,12 +60,14 @@ Intl.DateTimeFormatOptions(time_zone_name="short_offset").to_json()
|
|
|
55
60
|
#### Example usage
|
|
56
61
|
|
|
57
62
|
```python
|
|
58
|
-
import datetime
|
|
63
|
+
import datetime as dt
|
|
59
64
|
import python_intl as Intl
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
datetime = dt.datetime(2026, 8, 15)
|
|
62
67
|
formatter = Intl.DateTimeFormat("de-DE", {"year": "numeric", "month": "2-digit", "day": "2-digit"})
|
|
63
|
-
formatter.format(
|
|
68
|
+
formatter.format(datetime) # Will output the German format: "15.08.2026"
|
|
69
|
+
datetime_till = dt.datetime(2026, 9, 7)
|
|
70
|
+
formatter.format_range(datetime, datetime_till) # Will output the German format: "15.08. – 07.09.2026"
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
#### Compatibility
|
|
@@ -70,7 +77,7 @@ formatter.format(datetime_) # Will output the German format: "15.08.2026"
|
|
|
70
77
|
| `DateTimeFormat.format` | ✅ | |
|
|
71
78
|
| `DateTimeFormat.formatToParts` | ✅ | `DateTimeFormat.format_to_parts` |
|
|
72
79
|
| `DateTimeFormat.supportedLocalesOf` | ❌ | |
|
|
73
|
-
| `DateTimeFormat.formatRange` |
|
|
80
|
+
| `DateTimeFormat.formatRange` | ✅ | `DateTimeFormat.format_range` |
|
|
74
81
|
| `DateTimeFormat.formatRangeToParts` | ❌ | |
|
|
75
82
|
| `DateTimeFormat.resolvedOptions` | ❌ | |
|
|
76
83
|
|
|
@@ -8,6 +8,11 @@ the "same" code works on JavaScript and Python, with similar results.
|
|
|
8
8
|
**Status:** This is very much work in progress. Currently only `Intl.DateTimeFormat`
|
|
9
9
|
exists and this also is not complete yet.
|
|
10
10
|
|
|
11
|
+
**Note:** There are a lot of tests running the Python implementation against the
|
|
12
|
+
JavaScript one and comparing the results. In general things should be pretty
|
|
13
|
+
stable there. Still there are some cases with known differences. Also note
|
|
14
|
+
that results depend on the ICU version you have installed on your machine.
|
|
15
|
+
|
|
11
16
|
## General notes about the Python adaption
|
|
12
17
|
|
|
13
18
|
All names will be using the Python style rules. This means instead of
|
|
@@ -42,12 +47,14 @@ Intl.DateTimeFormatOptions(time_zone_name="short_offset").to_json()
|
|
|
42
47
|
#### Example usage
|
|
43
48
|
|
|
44
49
|
```python
|
|
45
|
-
import datetime
|
|
50
|
+
import datetime as dt
|
|
46
51
|
import python_intl as Intl
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
datetime = dt.datetime(2026, 8, 15)
|
|
49
54
|
formatter = Intl.DateTimeFormat("de-DE", {"year": "numeric", "month": "2-digit", "day": "2-digit"})
|
|
50
|
-
formatter.format(
|
|
55
|
+
formatter.format(datetime) # Will output the German format: "15.08.2026"
|
|
56
|
+
datetime_till = dt.datetime(2026, 9, 7)
|
|
57
|
+
formatter.format_range(datetime, datetime_till) # Will output the German format: "15.08. – 07.09.2026"
|
|
51
58
|
```
|
|
52
59
|
|
|
53
60
|
#### Compatibility
|
|
@@ -57,7 +64,7 @@ formatter.format(datetime_) # Will output the German format: "15.08.2026"
|
|
|
57
64
|
| `DateTimeFormat.format` | ✅ | |
|
|
58
65
|
| `DateTimeFormat.formatToParts` | ✅ | `DateTimeFormat.format_to_parts` |
|
|
59
66
|
| `DateTimeFormat.supportedLocalesOf` | ❌ | |
|
|
60
|
-
| `DateTimeFormat.formatRange` |
|
|
67
|
+
| `DateTimeFormat.formatRange` | ✅ | `DateTimeFormat.format_range` |
|
|
61
68
|
| `DateTimeFormat.formatRangeToParts` | ❌ | |
|
|
62
69
|
| `DateTimeFormat.resolvedOptions` | ❌ | |
|
|
63
70
|
|
|
@@ -431,3 +431,12 @@ class DateTimeFormat:
|
|
|
431
431
|
type="literal",
|
|
432
432
|
value="".join(literal_chars),
|
|
433
433
|
)
|
|
434
|
+
|
|
435
|
+
@cached_property
|
|
436
|
+
def _icu_dateinterval_format(self) -> icu.DateIntervalFormat: # ty: ignore[unresolved-attribute]
|
|
437
|
+
possible_skeletons = list(_options_to_possible_skeletons(self.options))
|
|
438
|
+
return icu.DateIntervalFormat.createInstance(possible_skeletons[0], self._icu_locale) # ty: ignore[unresolved-attribute]
|
|
439
|
+
|
|
440
|
+
def format_range(self, start_datetime: dt.datetime, end_datetime: dt.datetime) -> str:
|
|
441
|
+
icu_date_interval = icu.DateInterval(start_datetime, end_datetime) # ty: ignore[unresolved-attribute]
|
|
442
|
+
return self._icu_dateinterval_format.format(icu_date_interval)
|
|
File without changes
|
|
File without changes
|