times
Advanced tools
+2
-2
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.0 | ||
| Metadata-Version: 1.1 | ||
| Name: times | ||
| Version: 0.6.2 | ||
| Version: 0.7 | ||
| Summary: Times is a small, minimalistic, Python library for dealing with time conversions between universal time and arbitrary timezones. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/nvie/times/ |
+18
-27
@@ -1,36 +0,27 @@ | ||
| Times | ||
| ===== | ||
| **NOTE:** | ||
| This library will not be maintained any further. **You probably want to use | ||
| the excellent [Arrow](http://crsmithdev.com/arrow/) library.** | ||
| Build status: | ||
| [](http://travis-ci.org/nvie/times) | ||
| Times is a small, minimalistic, Python library for dealing with time | ||
| conversions to and from timezones, for once and for all. | ||
| > “There should be one—and preferably only one—obvious way to do it.” | ||
| It is designed to be simple and clear, but also opinionated about good and bad | ||
| practices. | ||
| In fact, version 0.7 of times has been rewritten to be implemented on top of | ||
| Arrow, so it still provides the Times interface, but you'll already be using | ||
| Arrow. You can probably easily replace your times function calls by Arrow | ||
| objects. | ||
| [Armin Ronacher][1] wrote about timezone best practices in his blog post | ||
| [Dealing with Timezones in Python][2]. The **tl;dr** summary is that | ||
| everything sucks about our mechanisms to represent absolute moments in time, | ||
| but the least worst one of all is UTC. | ||
| --- | ||
| [1]: http://twitter.com/mitsuhiko | ||
| [2]: http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/ | ||
| Times | ||
| ===== | ||
| Build status: | ||
| [](http://travis-ci.org/nvie/times) | ||
| [](https://coveralls.io/r/nvie/times?branch=master) | ||
| Rationale | ||
| --------- | ||
| Python's `datetime` library and the `pytz` library are powerful, but because | ||
| they don't prescribe a standard practice of working with dates, everybody is | ||
| free to pick his or her own way. | ||
| Times is a small, minimalistic, Python library for dealing with time | ||
| conversions to and from timezones, for once and for all. | ||
| `times` tries to make working with times and timezones a little less of | ||
| a clusterfuck and hopefully set a standard of some sort. | ||
| It still uses `datetime` and `pytz` under the covers, but as long as you never | ||
| use any timezone related stuff outside `times`, you should be safe. | ||
| Accepting time | ||
@@ -66,3 +57,3 @@ -------------- | ||
| `Times` utilizes the string parsing routines available in [dateutil][3]. Note | ||
| `Times` utilizes the string parsing routines available in [dateutil][1]. Note | ||
| that the source timezone is auto-detected from the string. If the string | ||
@@ -134,2 +125,2 @@ contains a timezone offset, you are not allowed to explicitly specify one. | ||
| [3]: http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2 | ||
| [1]: http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2 |
+4
-1
| [bdist_rpm] | ||
| requires = pytz | ||
| requires = arrow | ||
| [wheel] | ||
| universal = 1 | ||
| [egg_info] | ||
@@ -5,0 +8,0 @@ tag_build = |
+1
-2
@@ -1,2 +0,1 @@ | ||
| import sys | ||
| import os | ||
@@ -30,3 +29,3 @@ from setuptools import setup | ||
| platforms='any', | ||
| install_requires=['pytz >= 0a', 'python-dateutil >= 2.1'], | ||
| install_requires=['arrow'], | ||
| classifiers=[ | ||
@@ -33,0 +32,0 @@ # As from http://pypi.python.org/pypi?%3Aaction=list_classifiers |
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.0 | ||
| Metadata-Version: 1.1 | ||
| Name: times | ||
| Version: 0.6.2 | ||
| Version: 0.7 | ||
| Summary: Times is a small, minimalistic, Python library for dealing with time conversions between universal time and arbitrary timezones. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/nvie/times/ |
@@ -1,2 +0,1 @@ | ||
| pytz >= 0a | ||
| python-dateutil >= 2.1 | ||
| arrow |
+21
-38
@@ -0,6 +1,8 @@ | ||
| import datetime | ||
| import sys | ||
| import datetime | ||
| import calendar | ||
| import pytz | ||
| import arrow | ||
| from .version import VERSION | ||
| PY3 = sys.version_info[0] == 3 | ||
@@ -13,5 +15,2 @@ if PY3: | ||
| from dateutil.parser import parse | ||
| from .version import VERSION | ||
| __author__ = 'Vincent Driessen <vincent@3rdcloud.com>' | ||
@@ -22,3 +21,4 @@ __version__ = VERSION | ||
| def to_universal(local_dt, timezone=None): | ||
| """Converts the given local datetime or UNIX timestamp to a universal | ||
| """ | ||
| Converts the given local datetime or UNIX timestamp to a universal | ||
| datetime. | ||
@@ -28,8 +28,6 @@ """ | ||
| if timezone is not None: | ||
| raise ValueError( | ||
| 'Timezone argument illegal when using UNIX timestamps.' | ||
| ) | ||
| raise ValueError('Timezone argument illegal when using UNIX timestamps.') | ||
| return from_unix(local_dt) | ||
| elif isinstance(local_dt, string_types): | ||
| local_dt = parse(local_dt) | ||
| local_dt = arrow.get(local_dt).to('UTC').naive | ||
@@ -44,24 +42,12 @@ return from_local(local_dt, timezone) | ||
| if timezone is not None: | ||
| if local_dt.tzinfo is not None: | ||
| raise ValueError( | ||
| 'Cannot use timezone-aware datetime with explicit timezone ' | ||
| 'argument.' | ||
| ) | ||
| if isinstance(timezone, string_types): | ||
| timezone = pytz.timezone(timezone) | ||
| dt_with_tzinfo = timezone.localize(local_dt) | ||
| if timezone is None: | ||
| a = arrow.get(local_dt) | ||
| else: | ||
| if local_dt.tzinfo is None: | ||
| raise ValueError( | ||
| 'Explicit timezone required to convert naive datetimes.' | ||
| ) | ||
| dt_with_tzinfo = local_dt | ||
| univ_dt = dt_with_tzinfo.astimezone(pytz.utc) | ||
| return univ_dt.replace(tzinfo=None) | ||
| a = arrow.get(local_dt, timezone) | ||
| return a.to('UTC').naive | ||
| def from_unix(ut): | ||
| """Converts a UNIX timestamp, as returned by `time.time()`, to universal | ||
| """ | ||
| Converts a UNIX timestamp, as returned by `time.time()`, to universal | ||
| time. Assumes the input is in UTC, as `time.time()` does. | ||
@@ -72,8 +58,7 @@ """ | ||
| return datetime.datetime.utcfromtimestamp(float(ut)) | ||
| return arrow.get(ut).naive | ||
| def to_local(dt, timezone): | ||
| """Converts universal datetime to a local representation in given timezone. | ||
| """ | ||
| """Converts universal datetime to a local representation in given timezone.""" | ||
| if dt.tzinfo is not None: | ||
@@ -83,5 +68,5 @@ raise ValueError( | ||
| ) | ||
| if isinstance(timezone, string_types): | ||
| timezone = pytz.timezone(timezone) | ||
| return pytz.utc.localize(dt).astimezone(timezone) | ||
| if not isinstance(timezone, string_types): | ||
| raise TypeError('expected a timezone name (string), but got {} instead'.format(type(timezone))) | ||
| return arrow.get(dt).to(timezone).datetime | ||
@@ -94,3 +79,3 @@ | ||
| return calendar.timegm(dt.utctimetuple()) | ||
| return arrow.get(dt).timestamp | ||
@@ -100,4 +85,2 @@ | ||
| """Formats the given universal time for display in the given time zone.""" | ||
| if timezone is None: | ||
| raise ValueError('Please give an explicit timezone.') | ||
| local = to_local(dt, timezone) | ||
@@ -104,0 +87,0 @@ if fmt is None: |
+1
-1
@@ -1,1 +0,1 @@ | ||
| VERSION = '0.6.2' | ||
| VERSION = '0.7' |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
13282
-7.09%137
-11.61%