Closed wingfish closed 3 years ago
2021.6.4
@staticmethod
def random_datetime_this_month():
"""
生成一个属于当前月的随机日期时间
:return:
* random_date: (datetime) 个属于当前月的随机日期时间
举例如下::
print('--- GetRandomTime.random_datetime_this_month demo ---')
print(GetRandomTime.random_datetime_this_month)
print('---')
执行结果::
--- GetRandomTime.date_time_this_month demo demo ---
2018-07-01 12:47:20
---
"""
now = datetime.now()
begin_this_month = now.replace(
day=1, hour=0, minute=0, second=0, microsecond=0)
this_month_days = calendar.monthrange(now.year, now.month)
random_seconds = random.randint(0, this_month_days[1]*A_DAY_SECONDS)
random_date = begin_this_month + timedelta(seconds=random_seconds)
return random_date
2021.6.7 函数名和相关ut中的函数名都已经修改。 之后继续进行代码优化和ut的tc优化。
Class 名称修改为 RandomTime,动词Get放到下面的函数中 get_random_datetime_this_month get_random_datetime_this_year get_random_date_by_year get_random_date_by_range
docstring 和 代码都需要修改;
docstring 和 代码都需要修改;