Skip to content

Commit

Permalink
feat(ios): parsing opening hours
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaranski committed Nov 14, 2022
1 parent 16b0c58 commit 8328e3f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 33 deletions.
17 changes: 17 additions & 0 deletions ios/wheretopark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
68BBFAB4290EFC750012512D /* Swift-ISO8601-DurationParser in Frameworks */ = {isa = PBXBuildFile; productRef = 68BBFAB3290EFC750012512D /* Swift-ISO8601-DurationParser */; };
68BBFAB7290EFD600012512D /* DefaultCodable in Frameworks */ = {isa = PBXBuildFile; productRef = 68BBFAB6290EFD600012512D /* DefaultCodable */; };
68E2318E291569A3004EA1B2 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 68E23190291569A3004EA1B2 /* Localizable.strings */; };
68F7162E2922D5650040B942 /* OpeningHours in Frameworks */ = {isa = PBXBuildFile; productRef = 68F7162D2922D5650040B942 /* OpeningHours */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -91,6 +92,7 @@
68BBFAB4290EFC750012512D /* Swift-ISO8601-DurationParser in Frameworks */,
68BBFAB7290EFD600012512D /* DefaultCodable in Frameworks */,
68BBFAA7290ED8E40012512D /* PhoneNumberKit in Frameworks */,
68F7162E2922D5650040B942 /* OpeningHours in Frameworks */,
68BBFAAE290EED880012512D /* CodableGeoJSON in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -207,6 +209,7 @@
68BBFAAD290EED880012512D /* CodableGeoJSON */,
68BBFAB3290EFC750012512D /* Swift-ISO8601-DurationParser */,
68BBFAB6290EFD600012512D /* DefaultCodable */,
68F7162D2922D5650040B942 /* OpeningHours */,
);
productName = wheretopark;
productReference = 68239D9F290ED14200C25ED6 /* wheretopark.app */;
Expand Down Expand Up @@ -286,6 +289,7 @@
68BBFAAC290EED880012512D /* XCRemoteSwiftPackageReference "CodableGeoJSON" */,
68BBFAB2290EFC750012512D /* XCRemoteSwiftPackageReference "Swift-ISO8601-DurationParser" */,
68BBFAB5290EFD600012512D /* XCRemoteSwiftPackageReference "DefaultCodable" */,
68F7162C2922D5650040B942 /* XCRemoteSwiftPackageReference "opening-hours-swift" */,
);
productRefGroup = 68239DA0290ED14200C25ED6 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -761,6 +765,14 @@
minimumVersion = 1.0.0;
};
};
68F7162C2922D5650040B942 /* XCRemoteSwiftPackageReference "opening-hours-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "[email protected]:gbaranski/opening-hours-swift.git";
requirement = {
branch = master;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -784,6 +796,11 @@
package = 68BBFAB5290EFD600012512D /* XCRemoteSwiftPackageReference "DefaultCodable" */;
productName = DefaultCodable;
};
68F7162D2922D5650040B942 /* OpeningHours */ = {
isa = XCSwiftPackageProductDependency;
package = 68F7162C2922D5650040B942 /* XCRemoteSwiftPackageReference "opening-hours-swift" */;
productName = OpeningHours;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 68239D97290ED14100C25ED6 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"version" : "1.2.1"
}
},
{
"identity" : "opening-hours-swift",
"kind" : "remoteSourceControl",
"location" : "[email protected]:gbaranski/opening-hours-swift.git",
"state" : {
"branch" : "master",
"revision" : "d04206e0e0cf68ffb9732dda8ff792266371b570"
}
},
{
"identity" : "phonenumberkit",
"kind" : "remoteSourceControl",
Expand Down
59 changes: 29 additions & 30 deletions ios/wheretopark/DetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,35 @@ struct DetailsView: View {
}
}
Divider()
// VStack(alignment: .leading) {
// Text("parkingLot.hours")
// .fontWeight(.black)
// .font(.caption)
// .foregroundColor(.secondary)
// .textCase(.uppercase)
// // TODO: Use real status
// let status = ParkingLotStatus.closed
// switch status {
// case .opensSoon:
// Text(LocalizedStringKey("parkingLot.status.opensSoon"))
// .fontWeight(.heavy)
// .foregroundColor(.yellow)
// case .open:
// Text(LocalizedStringKey("parkingLot.status.open"))
// .fontWeight(.heavy)
// .foregroundColor(.green)
// case .closesSoon:
// Text(LocalizedStringKey("parkingLot.status.closesSoon"))
// .fontWeight(.heavy)
// .foregroundColor(.yellow)
// case .closed:
// Text(LocalizedStringKey("parkingLot.status.closed"))
// .fontWeight(.heavy)
// .foregroundColor(.red)
// // default:
// // fatalError("unknown status \(status)")
// }
// }
// Divider()
VStack(alignment: .leading) {
Text("parkingLot.hours")
.fontWeight(.black)
.font(.caption)
.foregroundColor(.secondary)
.textCase(.uppercase)
let status = parkingLot.metadata.status()
switch status {
case .opensSoon:
Text(LocalizedStringKey("parkingLot.status.opensSoon"))
.fontWeight(.heavy)
.foregroundColor(.yellow)
case .open:
Text(LocalizedStringKey("parkingLot.status.open"))
.fontWeight(.heavy)
.foregroundColor(.green)
case .closesSoon:
Text(LocalizedStringKey("parkingLot.status.closesSoon"))
.fontWeight(.heavy)
.foregroundColor(.yellow)
case .closed:
Text(LocalizedStringKey("parkingLot.status.closed"))
.fontWeight(.heavy)
.foregroundColor(.red)
// default:
// fatalError("unknown status \(status)")
}
}
Divider()
VStack(alignment: .leading) {
let formatter = RelativeDateTimeFormatter()
let lastUpdatedString = formatter.localizedString(for: parkingLot.state.lastUpdated, relativeTo: Date.now)
Expand Down
3 changes: 1 addition & 2 deletions ios/wheretopark/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ class ParkingLotAnnotation: NSObject, MKAnnotation {
}

var subtitle: String? {
// TODO: Change that
let status = ParkingLotStatus.closed
let status = parkingLot.metadata.status()
if status == .closed || status == .opensSoon {
return status.rawValue.capitalizingFirstLetter()
} else {
Expand Down
3 changes: 2 additions & 1 deletion ios/wheretopark/ParkingLot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ extension ParkingLotPricingRule: Decodable {
let values = try decoder.container(keyedBy: CodingKeys.self)
let durationString = try values.decode(String.self, forKey: .duration)
duration = DateComponents.durationFrom8601String(durationString)!
price = try values.decode(Decimal.self, forKey: .price)
let priceString = try values.decode(String.self, forKey: .price)
price = Decimal(string: priceString)!
repeating = try values.decodeIfPresent(Bool.self, forKey: .repeating) ?? false
}
}
Expand Down
15 changes: 15 additions & 0 deletions ios/wheretopark/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,27 @@ extension ParkingLotPricingRule {
}


import OpeningHours

extension ParkingLotMetadata {
var commentForLocale: String? {
let languageCode = Locale.current.language.languageCode?.identifier ?? "en"
let comment = comment[languageCode] ?? comment ["en"]
return comment
}

func status() -> ParkingLotStatus {
let rawOpeningHours = rules.map{ $0.hours }.joined(separator: "; ")
print("rawOpeningHours: \(rawOpeningHours)")
let openingHours = OpeningHours(rawOpeningHours)
let dateTime = now_at(timezone)
if openingHours.is_open(dateTime) {
return .open
} else {
return .closed
}

}
}

extension URL {
Expand Down

0 comments on commit 8328e3f

Please sign in to comment.