Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUCK] duration: 增加 一点五二小时 类的支持 #252

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading