Open TolemyW opened 4 years ago
def fake_date_between(self, start_date=None, end_date=None, format='%Y-%m-%d'): # 去掉时分秒,不然后续计算天差值会出错 today = datetime.datetime.strftime(datetime.datetime.today(), "%Y-%m-%d") today = datetime.datetime.strptime(today, '%Y-%m-%d') if start_date is None: start_diff = 'today' else: start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d') diff = (start_date - today).days start_diff = '%dd' % diff if diff != 0 else 'today' if end_date is None: end_diff = today else: end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d') diff = (end_date - today).days end_diff = '%sd' % diff if diff != 0 else 'today'
没明白什么意思,报什么错
plan_start_time||varchar(19)||计划开始时间[:date_between(2019-01-01, 2019-12-02, %Y-%m-%d)] plan_end_time||varchar(32)||计划结束时间[:date_between(2020-01-01, 2020-12-02, %Y-%m-%d)] 这样使用会报错
columns = self.fake_column(self.cur_num.value)
File "C:\ProgramData\Anaconda3\lib\site-packages\datafaker-0.7.4-py3.7.egg\datafaker\dbs\basedb.py", line 78, in fake_column
columns.append(self.fakedata.do_fake(item['cmd'], item['args'], current_num))
File "C:\ProgramData\Anaconda3\lib\site-packages\datafaker-0.7.4-py3.7.egg\datafaker\fakedata.py", line 238, in do_fake
return method(*args)
File "C:\ProgramData\Anaconda3\lib\site-packages\datafaker-0.7.4-py3.7.egg\datafaker\fakedata.py", line 100, in fake_date_between
return self.fake_date(start_diff, end_diff, format)
File "C:\ProgramData\Anaconda3\lib\site-packages\datafaker-0.7.4-py3.7.egg\datafaker\fakedata.py", line 78, in fake_date
thedate = self.faker.date_between(start_date, end_date)
File "C:\ProgramData\Anaconda3\lib\site-packages\faker-2.0.2-py3.7.egg\faker\providers\date_time__init.py", line 1584, in date_between
start_date = self._parse_date(start_date)
File "C:\ProgramData\Anaconda3\lib\site-packages\faker-2.0.2-py3.7.egg\faker\providers\date_time__init__.py", line 1543, in _parse_date
time_params = cls._parse_date_string(value)
File "C:\ProgramData\Anaconda3\lib\site-packages\faker-2.0.2-py3.7.egg\faker\providers\date_time\init__.py", line 1501, in _parse_date_string
raise ParseError("Can't parse date string {}
.".format(value))
faker.providers.date_time.ParseError: Can't parse date string 21d
.