@@ -50,6 +50,18 @@ class Delegate: NSObject, CLLocationManagerDelegate {
5050 ? " "
5151 : CNPostalAddressFormatter . string ( from: placemark!. postalAddress!, style: CNPostalAddressFormatterStyle . mailingAddress)
5252
53+ // Attempt to infer timezone for timestamp string
54+ var locatedTime : String ?
55+ if let locatedTimeZone = placemark? . timeZone {
56+ let time = location. timestamp
57+
58+ let formatter = DateFormatter ( )
59+ formatter. timeZone = locatedTimeZone
60+ formatter. dateFormat = " yyyy-MM-dd HH:mm:ss Z "
61+
62+ locatedTime = formatter. string ( from: time)
63+ }
64+
5365 switch format {
5466 case . json:
5567 let outputObject : [ String : String ? ] = [
@@ -75,6 +87,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
7587 " subThoroughfare " : placemark? . subThoroughfare,
7688 " region " : placemark? . region? . identifier,
7789 " timeZone " : placemark? . timeZone? . identifier,
90+ " time_local " : locatedTime,
7891
7992 // Address
8093 " address " : formattedPostalAddress
@@ -104,6 +117,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
104117 output = output. replacingOccurrences ( of: " %subThoroughfare " , with: String ( placemark? . subThoroughfare ?? " " ) )
105118 output = output. replacingOccurrences ( of: " %region " , with: String ( placemark? . region? . identifier ?? " " ) )
106119 output = output. replacingOccurrences ( of: " %timeZone " , with: String ( placemark? . timeZone? . identifier ?? " " ) )
120+ output = output. replacingOccurrences ( of: " %time_local " , with: String ( locatedTime ?? " " ) )
107121
108122 // Address
109123 output = output. replacingOccurrences ( of: " %address " , with: formattedPostalAddress)
@@ -198,6 +212,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
198212 %subThoroughfare Additional street-level information
199213 %region Reverse geocoded geographic region
200214 %timeZone Reverse geocoded time zone
215+ %time_local Localized time using reverse geocoded time zone
201216 -json Prints a JSON object with all information available
202217
203218 Default format if not specified is: %latitude %longitude.
@@ -220,7 +235,7 @@ for (i, argument) in ProcessInfo().arguments.enumerated() {
220235 case " -format " :
221236 if ProcessInfo ( ) . arguments. count > i+ 1 {
222237 delegate. format = . string( ProcessInfo ( ) . arguments [ i+ 1 ] )
223- let placemarkStrings = [ " %address " , " %name " , " %isoCountryCode " , " %country " , " %postalCode " , " %administrativeArea " , " %subAdministrativeArea " , " %locality " , " %subLocality " , " %thoroughfare " , " %subThoroughfare " , " %region " , " %timeZone " ]
238+ let placemarkStrings = [ " %address " , " %name " , " %isoCountryCode " , " %country " , " %postalCode " , " %administrativeArea " , " %subAdministrativeArea " , " %locality " , " %subLocality " , " %thoroughfare " , " %subThoroughfare " , " %region " , " %timeZone " , " %time_local " ]
224239 if placemarkStrings. contains ( where: ProcessInfo ( ) . arguments [ i+ 1 ] . contains) {
225240 delegate. requiresPlacemarkLookup = true
226241 }
0 commit comments