10000 Use inferred timezone for time field in output by AstroCB · Pull Request #31 · fulldecent/corelocationcli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use inferred timezone for time field in output #31

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

Merged
merged 4 commits into from
Aug 18, 2020
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
17 changes: 16 additions & 1 deletion CoreLocationCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ class Delegate: NSObject, CLLocationManagerDelegate {
? ""
: CNPostalAddressFormatter.string(from: placemark!.postalAddress!, style: CNPostalAddressFormatterStyle.mailingAddress)

// Attempt to infer timezone for timestamp string
var locatedTime: String?
if let locatedTimeZone = placemark?.timeZone {
let time = location.timestamp

let formatter = DateFormatter()
formatter.timeZone = locatedTimeZone
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"

locatedTime = formatter.string(from: time)
}

switch format {
case .json:
let outputObject: [String: String?] = [
Expand All @@ -75,6 +87,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
"subThoroughfare": placemark?.subThoroughfare,
"region": placemark?.region?.identifier,
"timeZone": placemark?.timeZone?.identifier,
"time_local": locatedTime,

// Address
"address": formattedPostalAddress
Expand Down Expand Up @@ -104,6 +117,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
output = output.replacingOccurrences(of: "%subThoroughfare", with: String(placemark?.subThoroughfare ?? ""))
output = output.replacingOccurrences(of: "%region", with: String(placemark?.region?.identifier ?? ""))
output = output.replacingOccurrences(of: "%timeZone", with: String(placemark?.timeZone?.identifier ?? ""))
output = output.replacingOccurrences(of: "%time_local", with: String(locatedTime ?? ""))

// Address
output = output.replacingOccurrences(of: "%address", with: formattedPostalAddress)
Expand Down Expand Up @@ -198,6 +212,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
%subThoroughfare Additional street-level information
%region Reverse geocoded geographic region
%timeZone Reverse geocoded time zone
%time_local Localized time using reverse geocoded time zone
-json Prints a JSON object with all information available

Default format if not specified is: %latitude %longitude.
Expand All @@ -220,7 +235,7 @@ for (i, argument) in ProcessInfo().arguments.enumerated() {
case "-format":
if ProcessInfo().arguments.count > i+1 {
delegate.format = .string(ProcessInfo().arguments[i+1])
let placemarkStrings = ["%address", "%name", "%isoCountryCode", "%country", "%postalCode", "%administrativeArea", "%subAdministrativeArea", "%locality", "%subLocality", "%thoroughfare", "%subThoroughfare", "%region", "%timeZone"]
let placemarkStrings = ["%address", "%name", "%isoCountryCode", "%country", "%postalCode", "%administrativeArea", "%subAdministrativeArea", "%locality", "%subLocality", "%thoroughfare", "%subThoroughfare", "%region", "%timeZone", "%time_local"]
if placemarkStrings.contains(where:ProcessInfo().arguments[i+1].contains) {
delegate.requiresPlacemarkLookup = true
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CoreLocationCLI [-follow] [-verbose] -json
| `%subThoroughfare` | additional street-level information |
| `%region` | Reverse geocoded geographic region |
| `%timeZone` | Reverse geocoded time zone |
| `%time_local` | Localized time using reverse geocoded time zone |

The default format is: `%latitude %longitude`.

Expand Down Expand Up @@ -74,7 +75,7 @@ The default format is: `%latitude %longitude`.
```

>```json
>{"address":"407 Keats Rd\nLower Moreland PA 19006\nUnited States","locality":"nLower Moreland","subThoroughfare":"407","time":"2019-10-03 04:10:05 +0000","subLocality":null,"administrativeArea":"PA","country":"United States","thoroughfare":"Keats Rd","region":"<+40.141196,-75.034815> radius 35.91","speed":"-1","latitude":"40.141196","name":"1354 Panther Rd","altitude":"92.00","timeZone":"America\/New_York","isoCountryCode":"US","longitude":"-75.034815","v_accuracy":"65","postalCode":"19006","direction":"-1.0","h_accuracy":"65","subAdministrativeArea":"Montgomery"}
>{"address":"407 Keats Rd\nLower Moreland PA 19006\nUnited States","locality":"nLower Moreland","subThoroughfare":"407","time":"2019-10-03 04:10:05 +0000","subLocality":null,"administrativeArea":"PA","country":"United States","thoroughfare":"Keats Rd","region":"<+40.141196,-75.034815> radius 35.91","speed":"-1","latitude":"40.141196","name":"1354 Panther Rd","altitude":"92.00","timeZone":"America\/New_York","time_local": "2019-10-02 23:10:05 -0400","isoCountryCode":"US","longitude":"-75.034815","v_accuracy":"65","postalCode":"19006","direction":"-1.0","h_accuracy":"65","subAdministrativeArea":"Montgomery"}
> ```

## Installation
Expand Down
0