我想要的是根据是否围绕固定的上下班时间来判断这是不是上下班记录
时间: 2024-02-17 10:04:02 浏览: 27
明白了,你的意思是要判断文本中的时间是否符合上下班的时间规律。以下是一个 Python 代码示例,可以实现这一功能:
```python
import re
def is_commute_record(text):
time_pattern = re.compile(r'\d{1,2}:\d{2}')
commute_pattern = re.compile(r'(上班|下班)')
has_time = bool(time_pattern.search(text))
has_commute = bool(commute_pattern.search(text))
if has_time and has_commute:
times = time_pattern.findall(text)
for t in times:
hour, minute = map(int, t.split(':'))
if (hour == 8 and minute <= 30) or (hour == 18 and minute >= 30):
return True
return False
else:
return False
```
这个函数仍然使用正则表达式来查找文本中的时间和上下班关键词。如果都存在,则继续判断时间是否符合上下班规律。这里假设上班时间为早上8点到8点30分,下班时间为下午6点到6点30分。如果文本中包含符合规律的时间,则返回 True,否则返回 False。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)