Update convertToTimeExpression function to handle edge cases and correct time validation

* **TimeExpression.swift**
  - Change the validation for 3-digit numbers to allow last two digits between 00-59.
  - Change the validation for 4-digit numbers to allow first two digits between 00-24 and last two digits between 00-59.

* **TimeExpressionTests.swift**
  - Update test cases to reflect the new validation rules.
  - Change test input "1360" to "2440" and update expected results accordingly.
  - Update assertions for the modified test cases.
This commit is contained in:
Miwa
2025-03-30 16:57:46 +09:00
parent 19dbbccd9f
commit feb5daa5bb
2 changed files with 6 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ extension KanaKanjiConverter {
if numberString.count == 3 {
let firstDigit = Int(numberString.prefix(1))!
let lastTwoDigits = Int(numberString.suffix(2))!
if (0...9).contains(firstDigit) && (0...60).contains(lastTwoDigits) {
if (0...9).contains(firstDigit) && (0...59).contains(lastTwoDigits) {
let timeExpression = "\(firstDigit):\(String(format: "%02d", lastTwoDigits))"
let candidate = Candidate(
text: timeExpression,
@@ -22,7 +22,7 @@ extension KanaKanjiConverter {
candidates.append(candidate)
}
} else if numberString.count == 4 {
if (0...12).contains(firstPart) && (0...60).contains(secondPart) {
if (0...24).contains(firstPart) && (0...59).contains(secondPart) {
let timeExpression = "\(String(format: "%02d", firstPart)):\(String(format: "%02d", secondPart))"
let candidate = Candidate(
text: timeExpression,