Removed swift date
This commit is contained in:
@@ -93,11 +93,35 @@ struct StatsController: RouteCollection {
|
||||
|
||||
|
||||
private func getStartOfMonth(month:Int, year:Int) -> Date {
|
||||
return Date(year: year, month: month, day: 0, hour: 0, minute: 0, second: 0, nanosecond: 0, region: .current)
|
||||
|
||||
let calendar = Calendar.current
|
||||
|
||||
var components = DateComponents()
|
||||
|
||||
components.day = 1
|
||||
components.month = month
|
||||
components.year = year
|
||||
components.hour = 0
|
||||
components.minute = 0
|
||||
|
||||
return calendar.date(from: components)!
|
||||
|
||||
|
||||
}
|
||||
|
||||
private func getEndOfMonth(month:Int, year:Int) -> Date {
|
||||
return Date(year: year, month: month + 1, day: -1, hour: 0, minute: 0, second: 0, nanosecond: 0, region: .ISO)
|
||||
let calendar = Calendar.current
|
||||
|
||||
var components = DateComponents()
|
||||
|
||||
components.day = -1
|
||||
components.month = month + 1
|
||||
components.year = year
|
||||
components.hour = 23
|
||||
components.minute = 59
|
||||
|
||||
return calendar.date(from: components)!
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -137,13 +161,26 @@ struct StatsController: RouteCollection {
|
||||
let year:Int
|
||||
}
|
||||
|
||||
var date = Date(year: 2020, month: 03, day: 01, hour: 0, minute: 0)
|
||||
let calendar = Calendar.current
|
||||
|
||||
var components = DateComponents()
|
||||
components.day = 01
|
||||
components.month = 03
|
||||
components.year = 2020
|
||||
components.hour = 0
|
||||
components.minute = 0
|
||||
|
||||
|
||||
|
||||
|
||||
var date = calendar.date(from: components)!
|
||||
var previousMonths:[MonthYear] = []
|
||||
|
||||
|
||||
repeat {
|
||||
//let stats = getStatsByMonth(year: date.year, month: date.month, req: req) //returns eventloopfuture<Stats>
|
||||
previousMonths.append(MonthYear(month: date.month, year: date.year))
|
||||
date = Calendar.current.date(byAdding: .month, value: 1, to: date)!.date
|
||||
date = Calendar.current.date(byAdding: .month, value: 1, to: date)!
|
||||
} while (date.month != (Date().month + 1) || date.year != Date().year)
|
||||
|
||||
|
||||
@@ -256,3 +293,16 @@ extension Double
|
||||
return Double(floor(pow(10.0, Double(places)) * self)/pow(10.0, Double(places)))
|
||||
}
|
||||
}
|
||||
|
||||
extension Date {
|
||||
|
||||
var month:Int {
|
||||
let calanderDate = Calendar.current.dateComponents([.day, .year, .month], from: self)
|
||||
return calanderDate.month ?? 1
|
||||
}
|
||||
|
||||
var year:Int {
|
||||
let calanderDate = Calendar.current.dateComponents([.day, .month, .year], from: self)
|
||||
return calanderDate.year ?? 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user