Esempio n. 1
0
def test_shiftByMonts():
    dt = datetime.datetime(2016, 6, 1, 12, 12, 12, 0, TZ_UTC)

    assert datetime_utils.shiftByMonths(dt, 0) == dt

    dt_plus2 = datetime.datetime(2016, 8, 1, 12, 12, 12, 0, TZ_UTC)
    dt_min2  = datetime.datetime(2016, 4, 1, 12, 12, 12, 0, TZ_UTC)
    assert datetime_utils.shiftByMonths(dt, 2) == dt_plus2
    assert datetime_utils.shiftByMonths(dt, -2) == dt_min2

    dt_plus7 = datetime.datetime(2017, 1, 1, 12, 12, 12, 0, TZ_UTC)
    dt_min7  = datetime.datetime(2015, 11, 1, 12, 12, 12, 0, TZ_UTC)
    assert datetime_utils.shiftByMonths(dt, 7) == dt_plus7
    assert datetime_utils.shiftByMonths(dt, -7) == dt_min7
Esempio n. 2
0
def test_get_all_from_date():
  dbcm = db._DBConnectionManager()
  dbc = dbcm.get_connection( 'unittest_database' )

  dao  = timeline_events_dao.TimelineEventDAO()
  cutoff_date = shiftByMonths(datetime.datetime(2016, 5,1,12,12,12), -3)
  t = dao.get_all_from_date(cutoff_date)

  assert len(t) == 11
Esempio n. 3
0
    def get_all_current_events(self, limit_count=0, limit_start=0):

        # Compare to end date to make sure periods are only not fetched,
        # if their end date is outside of the cutoff date
        #
        # If case of non-period events, start=end, so the logic is fine
        #
        cutoff_date = shiftByMonths(datetime.datetime.now(), -3)
        return self.get_all_from_date(cutoff_date, limit_count, limit_start)
Esempio n. 4
0
    def get_past_months(self, month_count):

        now = datetime.datetime.now()
        start_date = shiftByMonths(now, month_count*-1)

        sql = """
              SELECT  *
              FROM `pronto_statistic`
              WHERE ( %s = `pronto_statistic`.year AND %s <= `pronto_statistic`.month ) OR %s <= `pronto_statistic`.year
              ORDER BY year ASC, month ASC
              LIMIT %s;
        """
        params = ( int(start_date.year), int(start_date.month)+1, int(now.year), int(month_count) )

        return self._conn.execute_return_obj_list( ProntoStatistic, sql, params )



#1  2  3  4  5  6  7  8  9 10 11 12  1  2  3  4  5
#               1  2  3  4  5  6  7  8  9 10 11 12
Esempio n. 5
0
 def calculate_token_expiration_date(self):
     date = shiftByMonths( datetime.datetime.now(), int(Config.authentication['auth_token_expiration_period']) )
     return datetime_to_sql(date)