Skip to content

Commit

Permalink
duration: 增加 一点五二小时 类的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
du00cs committed Nov 18, 2024
1 parent af3a3f8 commit 71e919a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ trait Rules extends DimRules {

val ruleDurationDotNumeral = Rule(
name = "number.number grain",
pattern = List("(\\d+)\\.(\\d+)".regex, isDimension(TimeGrain).predicate),
pattern = List(isInteger.predicate, "[点\\.]".regex, or(isDimension(DigitSequence), isIntegerBetween(0, 9)).predicate, isDimension(TimeGrain).predicate),
prod = tokens {
case Token(_, GroupMatch(_ :: integer :: decimal :: _)) :: Token(_, GrainData(g, false, _)) :: _ =>
case (t1@ Token(_, nd: NumeralData)) :: _ :: Token(_, decimal) :: Token(_, GrainData(g, false, _)) :: _ =>
val (dOpt, length) = decimal match {
case ds: DigitSequenceData => (parseInt(ds.seq).toOption, ds.seq.length)
case nd: NumeralData => (getIntValue(nd.value).map(_.toInt), 1)
}
(for {
i <- parseInt(integer).toOption
d <- parseInt(decimal).toOption
i <- getIntValue(t1).map(_.toInt)
d <- dOpt
} yield {
val mden = math.pow(10, decimal.length).toInt
val mden = math.pow(10, length).toInt
val token: Option[Token] = g match {
case Grain.NoGrain => None
case Grain.Second => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object Examples extends DimExamples {
(DurationData(2000, Year, schema = Some("P2000Y")), List("两千年")),
(DurationData(30, Minute, schema = Some("PT0H30M")), List("半小时")),
(DurationData(30, Minute, schema = Some("PT30M")), List("0.5小时")),
(DurationData(90, Minute, schema = Some("PT90M")), List("1.5小时", "1.50小时", "一点五小时", "一点五零小时")),
(DurationData(30, Minute, schema = Some("PT30M")), List("30分钟", "半个钟头")),
(DurationData(12, Hour, schema = Some("P0DT12H")), List("半天")),
(DurationData(90, Minute, schema = Some("PT1H30M")), List("一个半小时", "一小时30分钟", "一个小时30分钟")),
Expand Down

0 comments on commit 71e919a

Please sign in to comment.