Skip to content

Commit

Permalink
time: 支持"下一个15号"
Browse files Browse the repository at this point in the history
  • Loading branch information
du00cs committed Nov 19, 2024
1 parent 75e4c6c commit 1abfe94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait Rules extends DimRules {
pattern = List(
"((这|今|本(?!现在))一?个?|明|上+一?个?|前一个?|(?<![一|查|看|搜|记|问|写])下+一?个?)".regex,
// ❌ 下周一早上 => 下[周一早上]
and(isDimension(Time), isNotLatent, not(isHint(Intersect, FinalRule)), not(isAPartOfDay)).predicate
and(isDimension(Time), not(isAPartOfDay)).predicate
),
prod = tokens {
case Token(RegexMatch, GroupMatch(s :: _)) :: (t @ Token(Time, td: TimeData)) :: _ =>
Expand All @@ -58,7 +58,9 @@ trait Rules extends DimRules {
case '上' => -1 * s.takeWhile(_ == '上').length
case '下' =>
val n = 1 * s.takeWhile(_ == '下').length
if (td.holiday.nonEmpty && n > 0) n - 1 else n
if (td.holiday.nonEmpty && n > 0) n - 1
else if (s.endsWith("")) n - 1
else n
}

val isValidCombination = s(0) match { // 病态表达验证
Expand All @@ -68,7 +70,7 @@ trait Rules extends DimRules {
case Day if td.form.contains(Weekend) => true // 本周末
case _ => false
}
case '上' | '下' => // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年
case '上' | '下' if !s.endsWith("")=> // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年
if (td.timeGrain == Day && td.holiday.isEmpty && !td.form.contains(Weekend) // 下周末是可以的
|| td.timeGrain == Year) false
else true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ object Examples extends DimExamples {
),
(datetime(LocalDateTime.of(2013, 2, 11, 4, 30, 0), Second), List("昨天现在")),
(datetime(LocalDateTime.of(2013, 2, 22, 8, 0, 0), Hour), List("下周五8点")),
(datetime(LocalDateTime.of(2013, 2, 15, 0, 0, 0), Day), List("下一个15号")),
(datetime(LocalDateTime.of(2013, 11, 20, 20, 0, 0), Hour), List("11.20 20点")),
(datetime(LocalDateTime.of(2013, 12, 24, 0, 0, 0), Day), List("圣诞节的前一天", "圣诞节前一天")),
(datetime(LocalDateTime.of(2013, 2, 12, 5, 5, 0), Minute), List("05分")),
Expand Down

0 comments on commit 1abfe94

Please sign in to comment.