コード例 #1
0
ファイル: test_dateranges.py プロジェクト: LionelR/alignak
    def test_standarddaterange_start_end_time(self):
        local_offset = time.timezone - 3600 * time.daylight  #TS below are for UTC
        local_hour_offset = local_offset / 3600
        if local_hour_offset >= 0:
            local_hour_offset = "-%02d" % local_hour_offset
        else:
            local_hour_offset = "+%02d" % -local_hour_offset
        data = {}
        for x in xrange(1, 3):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1435881600 + local_offset,
                'end': 1435967999 + local_offset
            }
        for x in xrange(4, 10):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1436486400 + local_offset,
                'end': 1436572799 + local_offset
            }
        for x in xrange(11, 17):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1437091200 + local_offset,
                'end': 1437177599 + local_offset
            }

        # Time from next wednesday morning to next wednesday night
        caldate = StandardDaterange('friday', '00:00-24:00')
        for date_now in data:
            with freeze_time(date_now, tz_offset=0):
                ret = caldate.get_start_and_end_time()
                print "* %s" % date_now
                self.assertEqual(data[date_now]['start'], ret[0])
                self.assertEqual(data[date_now]['end'], ret[1])
コード例 #2
0
ファイル: test_dateranges.py プロジェクト: pwgen/alignak
    def test_standarddaterange_start_end_time(self):
        local_offset = time.timezone - 3600 * time.daylight  #TS below are for UTC
        local_hour_offset = local_offset / 3600
        if local_hour_offset >= 0:
            local_hour_offset = "-%02d" % local_hour_offset
        else:
            local_hour_offset = "+%02d" % -local_hour_offset
        data = {}
        for x in xrange(1, 3):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1435881600 + local_offset,
                'end': 1435967999 + local_offset
            }
        for x in xrange(4, 10):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1436486400 + local_offset,
                'end': 1436572799 + local_offset
            }
        for x in xrange(11, 17):
            data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = {
                'start': 1437091200 + local_offset,
                'end': 1437177599 + local_offset
            }

        # Time from next wednesday morning to next wednesday night
        caldate = StandardDaterange('friday', '00:00-24:00')
        for date_now in data:
            with freeze_time(date_now, tz_offset=0):
                ret = caldate.get_start_and_end_time()
                print "* %s" % date_now
                self.assertEqual(data[date_now]['start'], ret[0])
                self.assertEqual(data[date_now]['end'], ret[1])
コード例 #3
0
ファイル: test_dateranges.py プロジェクト: jbiousse/alignak
    def test_standarddaterange_start_end_time(self):
        """ Test StandardDaterange.get_start_and_end_time to get start and end date of date range

        :return: None
        """
        local_offset = time.timezone - 3600 * time.daylight  # TS below are for UTC
        local_hour_offset = local_offset / 3600
        if local_hour_offset >= 0:
            local_hour_offset = "-%02d" % local_hour_offset
        else:
            local_hour_offset = "+%02d" % -local_hour_offset
        data = {}
        for num in range(1, 3):
            data['2015-07-%02d 01:50:00 %s' % (num, local_hour_offset)] = {
                'start': 1435881600 + local_offset,
                'end': 1435967999 + local_offset
            }
        for num in range(4, 10):
            data['2015-07-%02d 01:50:00 %s' % (num, local_hour_offset)] = {
                'start': 1436486400 + local_offset,
                'end': 1436572799 + local_offset
            }
        for num in range(11, 17):
            data['2015-07-%02d 01:50:00 %s' % (num, local_hour_offset)] = {
                'start': 1437091200 + local_offset,
                'end': 1437177599 + local_offset
            }

        # Time from next friday morning to next friday night
        caldate = StandardDaterange({'day': 'friday', 'other': '00:00-24:00'})
        for date_now in data:
            with freeze_time(date_now, tz_offset=0):
                # ret = caldate.get_start_and_end_time()
                # print("* %s" % date_now)
                # assert data[date_now]['start'] == ret[0]
                # assert data[date_now]['end'] == ret[1]
                start, end = caldate.get_start_and_end_time()
                print("-> res: %s (%s) - %s (%s)" % (start, type(start), end, type(end)))
                assert data[date_now]['start'] == start
                assert data[date_now]['end'] == end