@@ -921,7 +921,19 @@ def _check_limit_time_base(self, first_time_string, second_time_string,
921
921
else :
922
922
return first_full_time_handler
923
923
924
- def _adjust_underlying_future_time (self , time_string ):
924
+ def _adjust_underlying_future_time (
925
+ self , time_string , first_full_time_handler , second_full_time_handler ):
926
+ """
927
+
928
+ Args:
929
+ time_string: 时间字符串,进行未来时间扩展
930
+ first_full_time_handler: 假设不进行未来时间扩展,正常解析的时间起点
931
+ second_full_time_handler: 假设不进行未来时间扩展,正常解析的时间终点
932
+
933
+ Returns:
934
+ 扩展后的未来时间
935
+ """
936
+
925
937
# 检查哪些时间字符串可以被扩展为 未来字符串,并将其调节
926
938
ymd_time_patterns = [
927
939
# 时间点型
@@ -977,7 +989,29 @@ def _adjust_underlying_future_time(self, time_string):
977
989
time_string = '下' + time_string
978
990
979
991
elif matched_unit in ['时' , '点' ]:
980
- time_string = '明天' + time_string
992
+ # 此时需要判断 time_base 里的时,和字符串中的时,哪个发生在前,哪个在后。
993
+ # 如果 time_base 发生在前,如 [2023, 1, 6, 16, 30, 0], 而时间字符串为 “下午6点”
994
+ # 则此时不改变字符串,直接返回即可。
995
+ if first_full_time_handler [3 ] != - 1 and self .time_base_handler [3 ] != - 1 : # 小时时间均存在
996
+ if first_full_time_handler [3 ] > self .time_base_handler [3 ]: # 在 小时 字段符合不扩增至第二天的条件
997
+ pass
998
+ elif first_full_time_handler [3 ] < self .time_base_handler [3 ]: # 符合扩增条件
999
+ time_string = '明天' + time_string
1000
+ else : # 还需比较 分钟
1001
+
1002
+ if first_full_time_handler [4 ] != - 1 and self .time_base_handler [4 ] != - 1 : # 分钟时间均存在
1003
+ if first_full_time_handler [4 ] > self .time_base_handler [4 ]: # 在分钟字段不扩增
1004
+ pass
1005
+ elif first_full_time_handler [4 ] < self .time_base_handler [4 ]: # 符合扩增条件
1006
+ time_string = '明天' + time_string
1007
+ else :
1008
+ # 暂时不考虑 秒钟 ,此时直接将时间扩增至第二天
1009
+ time_string = '明天' + time_string
1010
+ else :
1011
+ time_string = '明天' + time_string
1012
+ else :
1013
+ # 时间基未指明,因此直接跨到第二天
1014
+ time_string = '明天' + time_string
981
1015
else :
982
1016
pass
983
1017
@@ -1082,7 +1116,8 @@ def parse_time_span_point(self, time_string):
1082
1116
# 检查 handler,确定是否按 ret_future 未来时间解析
1083
1117
if self .ret_future :
1084
1118
1085
- future_time_string = self ._adjust_underlying_future_time (time_string )
1119
+ future_time_string = self ._adjust_underlying_future_time (
1120
+ time_string , first_full_time_handler , second_full_time_handler )
1086
1121
first_full_time_handler , second_full_time_handler , time_type , blur_time = self .parse_time_point (
1087
1122
future_time_string , self .time_base_handler )
1088
1123
0 commit comments