Skip to content

Commit 530eb45

Browse files
committed
tox happy
1 parent a2d9245 commit 530eb45

1 file changed

Lines changed: 36 additions & 35 deletions

File tree

SoftLayer/managers/billing.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@ class BillingManager(object):
2020
:param SoftLayer.managers.orderingManager
2121
"""
2222

23-
def _format_date(self, date):
24-
"""format date.
25-
26-
:param dt: YY-MM-DD
27-
"""
28-
result = date.replace('T', ' ')
29-
return result[0:10]
30-
31-
def _get_month_delta(self, date1, date2):
32-
"""get month
33-
34-
:param date1: YY-MM-DD
35-
:param date2: YY-MM-DD
36-
:return: delta
37-
"""
38-
delta = 0
39-
while True:
40-
mdays = calendar.monthrange(date1.year, date1.month)[1]
41-
date1 += datetime.timedelta(days=mdays)
42-
if date1 <= date2:
43-
delta += 1
44-
else:
45-
break
46-
return delta
47-
4823
def __init__(self, client):
4924
"""init
5025
@@ -154,20 +129,19 @@ def list_resources(self, from_date=None, to_date=None, **kwargs):
154129

155130
if 'hourlyRecurringFee' not in item['billingItem']:
156131
create_date = datetime.datetime.strptime(
157-
self._format_date(
132+
format_date(
158133
item['billingItem']['createDate']), date_format)
159134
if cancellation_date:
160135
cancel_date = datetime.datetime.strptime(
161-
self._format_date(
136+
format_date(
162137
item['billingItem']['cancellationDate']),
163138
date_format)
164-
usedmonths = self._get_month_delta(create_date,
165-
cancel_date)
139+
usedmonths = get_month_delta(create_date, cancel_date)
166140
else:
167141
now = datetime.datetime.strptime(
168-
self._format_date(str(datetime.datetime.now())),
142+
format_date(str(datetime.datetime.now())),
169143
date_format)
170-
usedmonths = self._get_month_delta(create_date, now)
144+
usedmonths = get_month_delta(create_date, now)
171145

172146
usedmonths += 1
173147

@@ -189,14 +163,14 @@ def list_resources(self, from_date=None, to_date=None, **kwargs):
189163
'operation':
190164
item['billingItem']['id']}}}}})
191165
if virtual_guest:
192-
cost = virtual_guest[0]['billingItem']
193-
['currentHourlyCharge']
166+
cost = virtual_guest[0]['billingItem']['currentHourly' \
167+
'Charge']
194168

195169
else:
196170
create_date = datetime.datetime.strptime(
197-
self._format_date(creation_date), date_format)
171+
format_date(creation_date), date_format)
198172
cancel_date = datetime.datetime.strptime(
199-
self._format_date(cancellation_date), date_format)
173+
format_date(cancellation_date), date_format)
200174
d1_ts = time.mktime(create_date.timetuple())
201175
d2_ts = time.mktime(cancel_date.timetuple())
202176
usedhours = math.ceil(d2_ts - d1_ts)/3600
@@ -217,3 +191,30 @@ def list_resources(self, from_date=None, to_date=None, **kwargs):
217191
}
218192
result.append(resource)
219193
return result
194+
195+
196+
def format_date(date):
197+
"""format date.
198+
199+
:param date: YY-MM-DD
200+
"""
201+
result = date.replace('T', ' ')
202+
return result[0:10]
203+
204+
205+
def get_month_delta(date1, date2):
206+
"""get month
207+
208+
:param date1: YY-MM-DD
209+
:param date2: YY-MM-DD
210+
:return: delta
211+
"""
212+
delta = 0
213+
while True:
214+
mdays = calendar.monthrange(date1.year, date1.month)[1]
215+
date1 += datetime.timedelta(days=mdays)
216+
if date1 <= date2:
217+
delta += 1
218+
else:
219+
break
220+
return delta

0 commit comments

Comments
 (0)