@@ -119,16 +119,21 @@ extension Date {
119119
120120 /// Formats the current date as relative date if it's within a week of
121121 /// today, or with DateFormatter.Style.medium otherwise.
122+ /// - Parameter timeZone: An optional time zone used to adjust the date formatters. **NOTE**: This has no affect on relative time stamps.
122123 ///
123124 /// - Example: 22 hours from now
124125 /// - Example: 5 minutes ago
125126 /// - Example: 8 hours ago
126127 /// - Example: 2 days ago
127128 /// - Example: Jan 22, 2017
128129 ///
129- public func mediumString( ) -> String {
130+ public func mediumString( timeZone : TimeZone ? = nil ) -> String {
130131 let relativeFormatter = TTTTimeIntervalFormatter ( )
131132 let absoluteFormatter = DateFormatters . mediumDate
133+
134+ if let timeZone = timeZone {
135+ absoluteFormatter. timeZone = timeZone
136+ }
132137
133138 let components = Calendar . current. dateComponents ( [ . day] , from: self , to: Date ( ) )
134139 if let days = components. day, abs ( days) < 7 {
@@ -139,15 +144,20 @@ extension Date {
139144 }
140145
141146 /// Formats the current date as a medium relative date/time.
147+ /// - Parameter timeZone: An optional time zone used to adjust the date formatters.
142148 ///
143149 /// - Example: Tomorrow, 6:45 AM
144150 /// - Example: Today, 8:09 AM
145151 /// - Example: Yesterday, 11:36 PM
146152 /// - Example: Jan 28, 2017, 1:51 PM
147153 /// - Example: Jan 22, 2017, 2:18 AM
148154 ///
149- public func mediumStringWithTime( ) -> String {
150- return DateFormatters . mediumDateTime. string ( from: self )
155+ public func mediumStringWithTime( timeZone: TimeZone ? = nil ) -> String {
156+ let formatter = DateFormatters . mediumDateTime
157+ if let timeZone = timeZone {
158+ formatter. timeZone = timeZone
159+ }
160+ return formatter. string ( from: self )
151161 }
152162
153163 /// Formats the current date as (non relative) long date (no time) in UTC.
0 commit comments