@@ -50,6 +50,18 @@ class Delegate: NSObject, CLLocationManagerDelegate {
50
50
? " "
51
51
: CNPostalAddressFormatter . string ( from: placemark!. postalAddress!, style: CNPostalAddressFormatterStyle . mailingAddress)
52
52
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
+
53
65
switch format {
54
66
case . json:
55
67
let outputObject : [ String : String ? ] = [
@@ -75,6 +87,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
75
87
" subThoroughfare " : placemark? . subThoroughfare,
76
88
" region " : placemark? . region? . identifier,
77
89
" timeZone " : placemark? . timeZone? . identifier,
90
+ " time_local " : locatedTime,
78
91
79
92
// Address
80
93
" address " : formattedPostalAddress
@@ -104,6 +117,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
104
117
output = output. replacingOccurrences ( of: " %subThoroughfare " , with: String ( placemark? . subThoroughfare ?? " " ) )
105
118
output = output. replacingOccurrences ( of: " %region " , with: String ( placemark? . region? . identifier ?? " " ) )
106
119
output = output. replacingOccurrences ( of: " %timeZone " , with: String ( placemark? . timeZone? . identifier ?? " " ) )
120
+ output = output. replacingOccurrences ( of: " %time_local " , with: String ( locatedTime ?? " " ) )
107
121
108
122
// Address
109
123
output = output. replacingOccurrences ( of: " %address " , with: formattedPostalAddress)
@@ -198,6 +212,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
198
212
%subThoroughfare Additional street-level information
199
213
%region Reverse geocoded geographic region
200
214
%timeZone Reverse geocoded time zone
215
+ %time_local Localized time using reverse geocoded time zone
201
216
-json Prints a JSON object with all information available
202
217
203
218
Default format if not specified is: %latitude %longitude.
@@ -220,7 +235,7 @@ for (i, argument) in ProcessInfo().arguments.enumerated() {
220
235
case " -format " :
221
236
if ProcessInfo ( ) . arguments. count > i+ 1 {
222
237
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 " ]
224
239
if placemarkStrings. contains ( where: ProcessInfo ( ) . arguments [ i+ 1 ] . contains) {
225
240
delegate. requiresPlacemarkLookup = true
226
241
}
0 commit comments