Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust code style according to PEP8 and add OS Independent classifier #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions chronyk/chronyk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def _gmtime(timestamp):
try:
return time.gmtime(timestamp)
except OSError:
dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
dt = (datetime.datetime(1970, 1, 1) +
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parenthesis neither related to pep8 nor improve redability

datetime.timedelta(seconds=timestamp))
dst = int(_isdst(dt))
return time.struct_time(dt.timetuple()[:8] + tuple([dst]))

Expand All @@ -79,10 +80,12 @@ def _dtfromtimestamp(timestamp):
return datetime.datetime.fromtimestamp(timestamp)
except OSError:
timestamp -= time.timezone
dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
dt = (datetime.datetime(1970, 1, 1) +
datetime.timedelta(seconds=timestamp))
if _isdst(dt):
timestamp += 3600
dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
dt = (datetime.datetime(1970, 1, 1) +
datetime.timedelta(seconds=timestamp))
return dt


Expand All @@ -96,7 +99,8 @@ def _dfromtimestamp(timestamp):
d = datetime.date(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
if _isdst(d):
timestamp += 3600
d = datetime.date(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
d = (datetime.date(1970, 1, 1) +
datetime.timedelta(seconds=timestamp))
return d


Expand Down Expand Up @@ -310,7 +314,8 @@ def __fromrelative__(self, timestr):
match = re.match(r".*?([0-9]+?) month", timestr)
assert match is not None
months = int(match.group(1))
newyear = dati.year + int(((dati.month - 1) + months * coef) / 12)
newyear = (dati.year +
int(((dati.month - 1) + months * coef) / 12))
newmonth = (((dati.month - 1) + months * coef) % 12) + 1
newday = dati.day
while newday > calendar.monthrange(newyear, newmonth)[1]:
Expand Down Expand Up @@ -510,11 +515,11 @@ def datetime(self, timezone=None):
if timezone is None:
timezone = self.timezone
return _dtfromtimestamp(self.__timestamp__ - timezone)

def date(self, timezone=None):
"""Returns a datetime.date object.
This object retains all information, including timezones.

:param timezone = self.timezone
The timezone (in seconds west of UTC) to return the value in. By
default, the timezone used when constructing the class is used
Expand Down
30 changes: 16 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
import os
from setuptools import setup


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name = "Chronyk",
version = "1.0.1",
packages = ["chronyk"],
install_requires = [],
author = 'Felix "KoffeinFlummi" Wiegand',
author_email = "koffeinflummi@gmail.com",
description = "A library for parsing human-written times and dates.",
long_description = read("README.rst"),
license = "MIT",
keywords = "time date clock human parser timezone",
url = "https://github.com/KoffeinFlummi/Chronyk",
classifiers = [
name="Chronyk",
version="1.0.1",

packages=["chronyk"],
install_requires=[],

author='Felix "KoffeinFlummi" Wiegand',
author_email="koffeinflummi@gmail.com",
description="A library for parsing human-written times and dates.",
long_description=read("README.rst"),
license="MIT",
keywords="time date clock human parser timezone",
url="https://github.com/KoffeinFlummi/Chronyk",
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4"
Expand Down
Loading