From f1127b8f04bae2c0b293cdc2eff3169860f0c1f9 Mon Sep 17 00:00:00 2001 From: Scandie Date: Fri, 16 Nov 2018 17:41:03 +0200 Subject: [PATCH] Add rounding for timestamp of auction start date --- openprocurement/auction/plannings.py | 13 +++++-------- openprocurement/auction/utils.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/openprocurement/auction/plannings.py b/openprocurement/auction/plannings.py index 1b9a5dc..dce5de7 100644 --- a/openprocurement/auction/plannings.py +++ b/openprocurement/auction/plannings.py @@ -2,7 +2,7 @@ import iso8601 from datetime import datetime -from time import mktime, time +from time import time from gevent.subprocess import check_call from openprocurement.auction.systemd_msgs_ids import ( @@ -19,7 +19,7 @@ PreAnnounce_view ) from openprocurement.auction.utils import ( - do_until_success, prepare_auction_worker_cmd + do_until_success, prepare_auction_worker_cmd, get_timestamp ) @@ -49,8 +49,7 @@ def __iter__(self): start_date = start_date.astimezone(self.bridge.tz) auctions_start_in_date = startDate_view( self.bridge.db, - key=(mktime(start_date.timetuple()) + - start_date.microsecond / 1E6) * 1000 + key=get_timestamp(start_date) ) if datetime.now(self.bridge.tz) > start_date: LOGGER.info( @@ -90,8 +89,7 @@ def __iter__(self): start_date = start_date.astimezone(self.bridge.tz) auctions_start_in_date = startDate_view( self.bridge.db, - key=(mktime(start_date.timetuple()) + - start_date.microsecond / 1E6) * 1000 + key=get_timestamp(start_date) ) if datetime.now(self.bridge.tz) > start_date: LOGGER.info( @@ -196,8 +194,7 @@ def __iter__(self): start_date = start_date.astimezone(self.bridge.tz) auctions_start_in_date = startDate_view( self.bridge.db, - key=(mktime(start_date.timetuple()) + - start_date.microsecond / 1E6) * 1000 + key=get_timestamp(start_date) ) if datetime.now(self.bridge.tz) > start_date: LOGGER.info( diff --git a/openprocurement/auction/utils.py b/openprocurement/auction/utils.py index ce897b9..ecacbab 100644 --- a/openprocurement/auction/utils.py +++ b/openprocurement/auction/utils.py @@ -25,6 +25,7 @@ from fractions import Fraction from munch import Munch from zope.interface import implementer +from time import mktime from openprocurement.auction.interfaces import IFeedItem from openprocurement.auction.constants import DEFAULT_CONFIG @@ -482,3 +483,15 @@ def check_workers(plugins): if exceptions: raise exceptions[0] + + +def get_timestamp(date): + """ + Convert datetime.datetime object to timestamp + + :param date: date object + :type date: datetime.datetime + :return: timestamp in milliseconds + :rtype: int + """ + return int((mktime(date.timetuple()) + date.microsecond / 1E6) * 1000)