| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ Pendulum | |||
| 16 | 16 | ||
| 17 | 17 | Python datetimes made easy. | |
| 18 | 18 | ||
| 19 | - Supports Python **3.6+**. | ||
| 19 | + Supports Python **2.7** and **3.4+**. | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | .. code-block:: python | |
@@ -45,11 +45,11 @@ Supports Python **3.6+**. | |||
| 45 | 45 | '6 days 23 hours 58 minutes' | |
| 46 | 46 | ||
| 47 | 47 | # Proper handling of datetime normalization | |
| 48 | - >>> pendulum.create(2013, 3, 31, 2, 30, 0, 0, tz='Europe/Paris') | ||
| 48 | + >>> pendulum.datetime(2013, 3, 31, 2, 30, tz='Europe/Paris') | ||
| 49 | 49 | '2013-03-31T03:30:00+02:00' # 2:30 does not exist (Skipped time) | |
| 50 | 50 | ||
| 51 | 51 | # Proper handling of dst transitions | |
| 52 | - >>> just_before = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, tz='Europe/Paris') | ||
| 52 | + >>> just_before = pendulum.datetime(2013, 3, 31, 1, 59, 59, 999999, tz='Europe/Paris') | ||
| 53 | 53 | '2013-03-31T01:59:59.999999+01:00' | |
| 54 | 54 | >>> just_before.add(microseconds=1) | |
| 55 | 55 | '2013-03-31T03:00:00+02:00' | |
@@ -65,7 +65,7 @@ So it's still ``datetime`` but better. | |||
| 65 | 65 | ||
| 66 | 66 | Unlike other datetime libraries for Python, Pendulum is a drop-in replacement | |
| 67 | 67 | for the standard ``datetime`` class (it inherits from it), so, basically, you can replace all your ``datetime`` | |
| 68 | - instances by ``Pendulum`` instances in you code (exceptions exist for libraries that check | ||
| 68 | + instances by ``DateTime`` instances in you code (exceptions exist for libraries that check | ||
| 69 | 69 | the type of the objects by using the ``type`` function like ``sqlite3`` or ``PyMySQL`` for instance). | |
| 70 | 70 | ||
| 71 | 71 | It also removes the notion of naive datetimes: each ``Pendulum`` instance is timezone-aware | |
@@ -111,7 +111,7 @@ and it will try its best to return something while silently failing to handle so | |||
| 111 | 111 | -3599.999999 | |
| 112 | 112 | # Should be 1e-06 | |
| 113 | 113 | ||
| 114 | - just_before = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, 'Europe/Paris') | ||
| 114 | + just_before = pendulum.datetime(2013, 3, 31, 1, 59, 59, 999999, 'Europe/Paris') | ||
| 115 | 115 | just_after = just_before.add(microseconds=1) | |
| 116 | 116 | '2013-03-31T03:00:00+02:00' | |
| 117 | 117 | ||
@@ -125,7 +125,7 @@ behavior with the data you are passing to it. | |||
| 125 | 125 | Limitations | |
| 126 | 126 | =========== | |
| 127 | 127 | ||
| 128 | - Even though the ``Pendulum`` class is a subclass of ``datetime`` there are some rare cases where | ||
| 128 | + Even though the ``DateTime`` class is a subclass of ``datetime`` there are some rare cases where | ||
| 129 | 129 | it can't replace the native class directly. Here is a list (non-exhaustive) of the reported cases with | |
| 130 | 130 | a possible solution, if any: | |
| 131 | 131 | ||
@@ -172,8 +172,8 @@ a possible solution, if any: | |||
| 172 | 172 | Resources | |
| 173 | 173 | ========= | |
| 174 | 174 | ||
| 175 | - * `Official Website <http://pendulum.eustace.io>`_ | ||
| 176 | - * `Documentation <http://pendulum.eustace.io/docs/>`_ | ||
| 175 | + * `Official Website <https://pendulum.eustace.io>`_ | ||
| 176 | + * `Documentation <https://pendulum.eustace.io/docs/>`_ | ||
| 177 | 177 | * `Issue Tracker <https://github.com/sdispater/pendulum/issues>`_ | |
| 178 | 178 | ||
| 179 | 179 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | # Difference | |
| 2 | 2 | ||
| 3 | - The `diff()` method returns a :ref:`Period` instance that represents the total duration | ||
| 3 | + The `diff()` method returns a [Period](#period) instance that represents the total duration | ||
| 4 | 4 | between two `DateTime` instances. This interval can be then expressed in various units. | |
| 5 | 5 | These interval methods always return *the total difference expressed* in the specified time requested. | |
| 6 | 6 | All values are truncated and not rounded. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,3 +5,9 @@ Installing `pendulum` is quite simple: | |||
| 5 | 5 | ```bash | |
| 6 | 6 | $ pip install pendulum | |
| 7 | 7 | ``` | |
| 8 | + | ||
| 9 | + or, if you are using [poetry](https://poetry.eustace.io): | ||
| 10 | + | ||
| 11 | + ```bash | ||
| 12 | + $ poetry add pendulum | ||
| 13 | + ``` | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,9 @@ It otherwise can be a `Timezone` instance or simply a string timezone value. | |||
| 28 | 28 | ||
| 29 | 29 | !!!note | |
| 30 | 30 | ||
| 31 | - Supported strings for timezones are the one provided by the [IANA time zone database](https://www.iana.org/time-zones>). | ||
| 31 | + Supported strings for timezones are the one provided | ||
| 32 | + by the [IANA time zone database](https://www.iana.org/time-zones>). | ||
| 33 | + | ||
| 32 | 34 | The special `local` string is also supported and will return your current timezone. | |
| 33 | 35 | ||
| 34 | 36 | !!!warning | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,11 +36,11 @@ You can, however, control the normalization behavior: | |||
| 36 | 36 | >>> pendulum.datetime(2013, 3, 31, 2, 30, 0, 0, tz='Europe/Paris', | |
| 37 | 37 | dst_rule=pendulum.PRE_TRANSITION) | |
| 38 | 38 | '2013-03-31T01:30:00+01:00' | |
| 39 | - >>> pendulum.daettime(2013, 10, 27, 2, 30, 0, 0, tz='Europe/Paris', | ||
| 39 | + >>> pendulum.datetime(2013, 10, 27, 2, 30, 0, 0, tz='Europe/Paris', | ||
| 40 | 40 | dst_rule=pendulum.PRE_TRANSITION) | |
| 41 | 41 | '2013-10-27T02:30:00+02:00' | |
| 42 | 42 | ||
| 43 | - >>> pendulum.datetime(2013, 3, 31, 2, 30, 0, 0, tz='Europe/Paris' | ||
| 43 | + >>> pendulum.datetime(2013, 3, 31, 2, 30, 0, 0, tz='Europe/Paris', | ||
| 44 | 44 | dst_rule=pendulum.TRANSITION_ERROR) | |
| 45 | 45 | # NonExistingTime: The datetime 2013-03-31 02:30:00 does not exist | |
| 46 | 46 | >>> pendulum.datetime(2013, 10, 27, 2, 30, 0, 0, tz='Europe/Paris', | |
@@ -70,7 +70,7 @@ adopt the proper behavior and apply the transition accordingly. | |||
| 70 | 70 | '2013-03-31T01:59:59.999998+01:00' | |
| 71 | 71 | ||
| 72 | 72 | >>> dt = pendulum.datetime(2013, 10, 27, 2, 59, 59, 999999, | |
| 73 | - tz='Europe/Paris' | ||
| 73 | + tz='Europe/Paris', | ||
| 74 | 74 | dst_rule=pendulum.PRE_TRANSITION) | |
| 75 | 75 | '2013-10-27T02:59:59.999999+02:00' | |
| 76 | 76 | >>> dt = dt.add(microseconds=1) | |
@@ -99,6 +99,16 @@ with the `in_timezone()` method. | |||
| 99 | 99 | ||
| 100 | 100 | ## Using the timezone library directly | |
| 101 | 101 | ||
| 102 | + !!!warning | ||
| 103 | + | ||
| 104 | + **You should avoid using the timezone library in Python < 3.6.** | ||
| 105 | + | ||
| 106 | + This is due to the fact that Pendulum relies heavily on the presence | ||
| 107 | + of the `fold` attribute which was introduced in Python 3.6. | ||
| 108 | + | ||
| 109 | + The reason it works inside the Pendulum ecosystem is that it | ||
| 110 | + backported the `fold` attribute in the `DateTime` class. | ||
| 111 | + | ||
| 102 | 112 | Like said in the introduction, you can use the timezone library | |
| 103 | 113 | directly with standard `datetime` objects but with limitations, especially | |
| 104 | 114 | when adding and subtracting time around transition times. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments