@@ -98,38 +98,23 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
9898 /// - endDate: Date on which the `period` for which data you're interested in **is ending**.
9999 /// e.g. if you want data spanning 11-17 Feb 2019, you should pass in a period of `.week` and an
100100 /// ending date of `Feb 17 2019`.
101- /// - timeZone: The time zone in which the dates are represented.
102101 /// - limit: Limit of how many objects you want returned for your query. Default is `10`. `0` means no limit.
103102 open func getData< TimeStatsType: StatsTimeIntervalData > (
104103 period: StatsPeriodUnit ,
105104 unit: StatsPeriodUnit ? = nil ,
106105 startDate: Date ? = nil ,
107106 endDate: Date ,
108- timeZone: TimeZone ? = nil ,
109107 limit: Int = 10 ,
110108 fields: [ String ] ? = nil ,
111109 completion: @escaping ( ( TimeStatsType ? , Error ? ) -> Void )
112110 ) {
113111 let pathComponent = TimeStatsType . pathComponent
114112 let path = self . path ( forEndpoint: " sites/ \( siteID) / \( pathComponent) / " , withVersion: . _1_1)
115113
116- func formattedDate( _ date: Date ) -> String {
117- guard let timeZone else {
118- // For backward-compatibility, use the existing periodDataQueryDateFormatter
119- // with the current time zone.
120- return periodDataQueryDateFormatter. string ( from: date)
121- }
122- let formatter = DateFormatter ( )
123- formatter. locale = Locale ( identifier: " en_US_POSIX " )
124- formatter. dateFormat = " yyyy-MM-dd "
125- formatter. timeZone = timeZone
126- return formatter. string ( from: date)
127- }
128-
129114 var properties = [
130115 " period " : period. stringValue,
131116 " unit " : unit? . stringValue ?? period. stringValue,
132- " date " : formattedDate ( endDate)
117+ " date " : periodDataQueryDateFormatter . string ( from : endDate)
133118 ] as [ String : Any ]
134119
135120 for (key, value) in TimeStatsType . queryProperties ( period: unit ?? period, maxCount: limit) {
@@ -138,7 +123,7 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
138123
139124 if let startDate {
140125 properties [ " period " ] = nil
141- properties [ " start_date " ] = formattedDate ( startDate)
126+ properties [ " start_date " ] = periodDataQueryDateFormatter . string ( from : startDate)
142127 }
143128 if let fields {
144129 properties [ " stat_fields " ] = fields. joined ( separator: " , " )
@@ -304,6 +289,9 @@ extension StatsServiceRemoteV2 {
304289
305290 private func startDate( for period: StatsPeriodUnit , endDate: Date ) -> Date {
306291 switch period {
292+ case . hour:
293+ assertionFailure ( " unsupported period: \( period) " )
294+ return calendarForSite. startOfDay ( for: endDate)
307295 case . day:
308296 return calendarForSite. startOfDay ( for: endDate)
309297 case . week:
@@ -425,6 +413,8 @@ extension StatsTimeIntervalData {
425413public extension StatsPeriodUnit {
426414 var stringValue : String {
427415 switch self {
416+ case . hour:
417+ return " hour "
428418 case . day:
429419 return " day "
430420 case . week:
@@ -438,6 +428,8 @@ public extension StatsPeriodUnit {
438428
439429 init ? ( string: String ) {
440430 switch string {
431+ case " hour " :
432+ self = . hour
441433 case " day " :
442434 self = . day
443435 case " week " :
0 commit comments