Exemplo n.º 1
0
    def test_get_datetime_object(self):
        """
        Test get_datetime_object method creates proper datetime.datetime or
        datetime.time object given the proper string
        """
        # test full date
        date_test = '1970-01-02 03:04:05'
        exp_dt_obj = datetime.datetime(1970, 1, 2, 3, 4, 5)
        result = TimeWindow.get_datetime_object(date_test)
        self.assertEqual(exp_dt_obj, result)

        # test timestamp with hours, minutes seconds
        time_test1 = '01:02:03'
        exp_tm_obj1 = datetime.time(1, 2, 3)
        result = TimeWindow.get_datetime_object(time_test1)
        self.assertEqual(exp_tm_obj1, result)

        # test timestamp with hours, minutes
        time_test2 = '03:04'
        exp_tm_obj2 = datetime.time(3, 4)
        result = TimeWindow.get_datetime_object(time_test2)
        self.assertEqual(exp_tm_obj2, result)

        # test timestamp with single-digit hour, minutes
        time_test3 = '5:06'
        exp_tm_obj3 = datetime.time(5, 6)
        result = TimeWindow.get_datetime_object(time_test3)
        self.assertEqual(exp_tm_obj3, result)
Exemplo n.º 2
0
    def test_get_datetime_object(self):
        """
        Test get_datetime_object method creates proper datetime.datetime or
        datetime.time object given the proper string
        """
        # test full date
        date_test = '1970-01-02 03:04:05'
        exp_dt_obj = datetime.datetime(1970, 1, 2, 3, 4, 5)
        result = TimeWindow.get_datetime_object(date_test)
        self.assertEqual(exp_dt_obj, result)

        # test timestamp with hours, minutes seconds
        time_test1 = '01:02:03'
        exp_tm_obj1 = datetime.time(1, 2, 3)
        result = TimeWindow.get_datetime_object(time_test1)
        self.assertEqual(exp_tm_obj1, result)

        # test timestamp with hours, minutes
        time_test2 = '03:04'
        exp_tm_obj2 = datetime.time(3, 4)
        result = TimeWindow.get_datetime_object(time_test2)
        self.assertEqual(exp_tm_obj2, result)

        # test timestamp with single-digit hour, minutes
        time_test3 = '5:06'
        exp_tm_obj3 = datetime.time(5, 6)
        result = TimeWindow.get_datetime_object(time_test3)
        self.assertEqual(exp_tm_obj3, result)
Exemplo n.º 3
0
    def _parse_data(self, gut_data):
        """
        :type gut_data: dict
        """
        start_data = gut_data.get(u'start', None)
        self._log.debug('raw start from zk is "{0}"'.format(start_data))
        if start_data is not None:
            self._start = TimeWindow.get_datetime_object(start_data)
            
        stop_data = gut_data.get(u'stop', None)
        self._log.debug('raw stop from zk is "{0}"'.format(stop_data))

        if stop_data is not None:
            self._stop = TimeWindow.get_datetime_object(stop_data)

        if start_data is None and stop_data is None:
            self._log.error('Start and Stop time not specified!')
        
        self._log.info('The current time is: {0}. Start time is: {1}. '
                       'Stop time is: {2}'
                       .format(self.current_time, self._start, self._stop))