Skip to content

Commit 4faa7a4

Browse files
committed
Better handling of pressure tendency remarks ("5 group")
* Pressure change value is negated for downwards trends * Localized string fixed to indicate pressure value is a change
1 parent b4c209d commit 4faa7a4

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Sources/METARFormatting/Formatters/Remark/Remark.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public extension Remark {
4545
public var pressureFormat = Measurement<UnitPressure>.FormatStyle(
4646
width: .abbreviated,
4747
usage: .asProvided,
48-
numberFormatStyle: .number.precision(.fractionLength(0)))
48+
numberFormatStyle: .number.precision(.fractionLength(1)))
4949

5050
/// The format to use when printing wind information.
5151
public var windFormat = Wind.FormatStyle()
@@ -172,7 +172,7 @@ public extension Remark {
172172
return ListFormatStyle.list(memberStyle: .event(dateFormat: dateFormat), type: .and).format(events)
173173

174174
case let .pressureTendency(character, _):
175-
return String(localized: "\(character, format: .pressureCharacter) (currently \(value.pressureMeasurement!, format: pressureFormat))", comment: "remark")
175+
return String(localized: "\(character, format: .pressureCharacter) (change: \(value.pressureMeasurement!, format: pressureFormat))", comment: "remark")
176176

177177
case let .rapidPressureChange(change):
178178
switch change {

Sources/SwiftMETAR/Remarks/Parsers/Types/PressureTendencyParser.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@ import Foundation
33

44
final class PressureTendencyParser: RemarkParser {
55
var urgency = Remark.Urgency.routine
6-
6+
77
private let characterRef = Reference<Remark.PressureCharacter>()
88
private let amountRef = Reference<Float>()
9-
9+
1010
private lazy var rx = Regex {
1111
Anchor.wordBoundary
1212
"5"
1313
Capture(as: characterRef) { try! Remark.PressureCharacter.rx } transform: { .init(rawValue: String($0))! }
1414
Capture(as: amountRef) { Repeat(.digit, count: 3) } transform: { Float($0)!/10.0 }
1515
Anchor.wordBoundary
1616
}
17-
17+
1818
func parse(remarks: inout String, date: DateComponents) throws -> Remark? {
1919
guard let result = try rx.firstMatch(in: remarks) else { return nil }
20-
21-
let character = result[characterRef],
22-
amount = result[amountRef]
23-
20+
21+
let character = result[characterRef]
22+
var amount = result[amountRef]
23+
24+
switch character {
25+
case .inflectedDown, .deceleratingDown, .steadyDown, .acceleratingDown:
26+
amount *= -1
27+
default: break
28+
29+
}
30+
2431
remarks.removeSubrange(result.range)
2532
return .pressureTendency(character: character, change: amount)
2633
}

0 commit comments

Comments
 (0)