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

Develop #27

Merged
merged 6 commits into from
Aug 11, 2016
Merged
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
29 changes: 9 additions & 20 deletions datetimerange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""

from __future__ import division
import datetime

import dataproperty as dp
Expand Down Expand Up @@ -44,19 +45,6 @@ class DateTimeRange(object):
.. seealso:: :py:meth:`.get_end_time_str`
"""

__COMMON_DST_TIMEZONE_TABLE = {
-36000: "America/Adak", # -1000
-32400: "US/Alaska", # -0900
-28800: "US/Pacific", # -0800
-25200: "US/Mountain", # -0700
-21600: "US/Central", # -0600
-18000: "US/Eastern", # -0500
-14400: "Canada/Atlantic", # -0400
-12600: "America/St_Johns", # -0330
-10800: "America/Miquelon", # -0300
7200: "Africa/Tripoli", # 0200
}

NOT_A_TIME_STR = "NaT"

def __init__(
Expand All @@ -79,7 +67,7 @@ def __repr__(self):
]

if self.is_output_elapse:
suffix = " (%s)" % (self.end_datetime - self.start_datetime)
suffix = " ({})".format(self.end_datetime - self.start_datetime)
else:
suffix = ""

Expand Down Expand Up @@ -289,7 +277,7 @@ def validate_time_inversion(self):
raise TypeError

if self.start_datetime > self.end_datetime:
message = "time inversion found: %s > %s" % (
message = "time inversion found: {:s} > {:s}".format(
str(self.start_datetime), str(self.end_datetime))
raise ValueError(message)

Expand Down Expand Up @@ -614,11 +602,13 @@ def range(self, step):
if not is_inversion:
if self.__compare_timedelta(step, seconds=0) < 0:
raise ValueError(
"invalid step: expect greater than 0, actual=%s" % (step))
"invalid step: expect greater than 0, actual={}".format(
step))
else:
if self.__compare_timedelta(step, seconds=0) > 0:
raise ValueError(
"invalid step: expect less than 0, actual=%s" % (step))
"invalid step: expect less than 0, actual={}".format(
step))

current_datetime = self.start_datetime
while current_datetime <= self.end_datetime:
Expand Down Expand Up @@ -728,8 +718,7 @@ def truncate(self, percentage):
if percentage == 0:
return

discard_time = self.timedelta // int(100) * \
int(percentage / 2.0)
discard_time = self.timedelta // int(100) * int(percentage / 2)

self.__start_datetime += discard_time
self.__end_datetime -= discard_time
Expand All @@ -742,4 +731,4 @@ def __validate_value(self, data_prop):
def __get_timedelta_sec(dt):
return int(
dt.days * 60 ** 2 * 24 + float(dt.seconds) +
float(dt.microseconds / (1000.0 ** 2)))
dt.microseconds / (1000.0 ** 2))
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DataProperty>=0.7.0
DataProperty>=0.8.1
python-dateutil>=2.5.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setuptools.setup(
name="DateTimeRange",
version="0.2.4",
version="0.2.5",
author="Tsuyoshi Hombashi",
author_email="gogogo.vm@gmail.com",
url="https://github.com/thombashi/DateTimeRange",
Expand Down