mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
Add convertToTimeExpression function to convert numbers into time expressions
* Add logic to handle 3-digit and 4-digit numbers * Check if the number is 3 digits with the first digit between 0-9 and the last two digits between 00-60 * Check if the number is 4 digits with the first two digits between 00-24 and the last two digits between 00-59 * Convert the number into a time expression in the format 'HH:MM' if conditions are met
This commit is contained in:
@@ -4,8 +4,6 @@ extension KanaKanjiConverter {
|
||||
func convertToTimeExpression(_ inputData: ComposingText) -> [Candidate] {
|
||||
var candidates: [Candidate] = []
|
||||
let numberString = inputData.convertTarget
|
||||
let firstPart = Int(numberString.prefix(2))!
|
||||
let secondPart = Int(numberString.suffix(2))!
|
||||
|
||||
if numberString.count == 3 {
|
||||
let firstDigit = Int(numberString.prefix(1))!
|
||||
@@ -22,8 +20,10 @@ extension KanaKanjiConverter {
|
||||
candidates.append(candidate)
|
||||
}
|
||||
} else if numberString.count == 4 {
|
||||
if (0...24).contains(firstPart) && (0...59).contains(secondPart) {
|
||||
let timeExpression = "\(String(format: "%02d", firstPart)):\(String(format: "%02d", secondPart))"
|
||||
let firstTwoDigits = Int(numberString.prefix(2))!
|
||||
let lastTwoDigits = Int(numberString.suffix(2))!
|
||||
if (0...24).contains(firstTwoDigits) && (0...59).contains(lastTwoDigits) {
|
||||
let timeExpression = "\(String(format: "%02d", firstTwoDigits)):\(String(format: "%02d", lastTwoDigits))"
|
||||
let candidate = Candidate(
|
||||
text: timeExpression,
|
||||
value: -10,
|
||||
|
||||
Reference in New Issue
Block a user