Skip to content

Commit

Permalink
fixed local time / utc time
Browse files Browse the repository at this point in the history
  • Loading branch information
mtill committed Oct 3, 2018
1 parent de658c0 commit a6e100b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def addNewItem():
thecategory=thecategory,
thenote=thenote)

amountcurrency = str(newItem['amount']) + newItem['currency']
amountcurrency = '{:.2f}'.format(newItem['amount']) + newItem['currency']
thecategory = '' if newItem['category'] == 'nicht kategorisiert' else newItem['category']
htmlentry = template('categoryItem.tpl',
date=thedate,
Expand Down Expand Up @@ -179,3 +179,4 @@ def getDetails():
else:
print('using cherrypy engine')
run(app, server='cherrypy', host='0.0.0.0', port=8080)

12 changes: 5 additions & 7 deletions kontomodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ def getTransactions(self, accounts, fromDate, toDate):
hasParams = False
if fromDate is not None:
timestampsql = timestampsql + 'timestamp>=? AND '
fromDateTimestamp = fromDate.timestamp()
fromDateTimestamp = calendar.timegm(fromDate.utctimetuple())
sqlparam.append(fromDateTimestamp)
hasParams = True
if toDate is not None:
timestampsql = timestampsql + 'timestamp<=? AND '
toDateTimestamp = toDate.timestamp()
timestampsql = timestampsql + 'timestamp<? AND '
toDateTimestamp = calendar.timegm((toDate + datetime.timedelta(days=1)).utctimetuple())
sqlparam.append(toDateTimestamp)
hasParams = True

print()
accountsql = ''
if accounts is not None:
sqlparam.extend(accounts)
Expand All @@ -118,10 +119,8 @@ def getTransactions(self, accounts, fromDate, toDate):

thecategory = '' if c['category'] is None else c['category']
thenote = '' if c['note'] is None else c['note']
dt = datetime.datetime.fromtimestamp(c['timestamp'])
ctimestamp = calendar.timegm(dt.utctimetuple())
result.append({'id': c['id'],
'timestamp': ctimestamp,
'timestamp': c['timestamp'],
'account': c['account'],
'amount': float(c['amount']),
'currency': c['currency'],
Expand All @@ -135,7 +134,6 @@ def getTransactions(self, accounts, fromDate, toDate):
# returns newly added item
def addItem(self, thedate, theaccount, theamount, thecurrency, thename, thedescription, thecategory, thenote):
timestamp = calendar.timegm(datetime.datetime.strptime(thedate, '%Y-%m-%d').utctimetuple())

self.cursor.execute('INSERT INTO transactions (account,timestamp,amount,currency,name,description,category,note,id) VALUES (?,?,?,?,?,?,?,?,NULL)', (theaccount, timestamp, theamount, thecurrency, thename, thedescription, thecategory, thenote))
theid = self.cursor.execute('SELECT last_insert_rowid()').fetchone()[0]
self.conn.commit()
Expand Down

0 comments on commit a6e100b

Please sign in to comment.