FIX: date range was inconsistent for admin dashboard reports

This commit is contained in:
Arpit Jalan 2018-04-08 16:49:41 +05:30
parent cd66dd1404
commit f5febe5843
3 changed files with 7 additions and 7 deletions

View File

@ -161,8 +161,8 @@ Report.reopenClass({
}).then(json => { }).then(json => {
// Add zero values for missing dates // Add zero values for missing dates
if (json.report.data.length > 0) { if (json.report.data.length > 0) {
const startDateFormatted = moment(json.report.start_date).format('YYYY-MM-DD'); const startDateFormatted = moment(json.report.start_date).utc().format('YYYY-MM-DD');
const endDateFormatted = moment(json.report.end_date).format('YYYY-MM-DD'); const endDateFormatted = moment(json.report.end_date).utc().format('YYYY-MM-DD');
json.report.data = fillMissingDates(json.report.data, startDateFormatted, endDateFormatted); json.report.data = fillMissingDates(json.report.data, startDateFormatted, endDateFormatted);
} }

View File

@ -12,8 +12,8 @@ export default Discourse.Route.extend({
model: model, model: model,
categoryId: (model.get('category_id') || 'all'), categoryId: (model.get('category_id') || 'all'),
groupId: model.get('group_id'), groupId: model.get('group_id'),
startDate: moment(model.get('start_date')).format('YYYY-MM-DD'), startDate: moment(model.get('start_date')).utc().format('YYYY-MM-DD'),
endDate: moment(model.get('end_date')).format('YYYY-MM-DD') endDate: moment(model.get('end_date')).utc().format('YYYY-MM-DD')
}); });
} }
}); });

View File

@ -142,8 +142,8 @@ module Jobs
def report_export def report_export
return enum_for(:report_export) unless block_given? return enum_for(:report_export) unless block_given?
@extra[:start_date] = @extra[:start_date].to_date if @extra[:start_date].is_a?(String) @extra[:start_date] = @extra[:start_date].to_date.beginning_of_day if @extra[:start_date].is_a?(String)
@extra[:end_date] = @extra[:end_date].to_date if @extra[:end_date].is_a?(String) @extra[:end_date] = @extra[:end_date].to_date.end_of_day if @extra[:end_date].is_a?(String)
@extra[:category_id] = @extra[:category_id].present? ? @extra[:category_id].to_i : nil @extra[:category_id] = @extra[:category_id].present? ? @extra[:category_id].to_i : nil
@extra[:group_id] = @extra[:group_id].present? ? @extra[:group_id].to_i : nil @extra[:group_id] = @extra[:group_id].present? ? @extra[:group_id].to_i : nil
@ -152,7 +152,7 @@ module Jobs
report_hash[row[:x].to_s(:db)] = row[:y].to_s(:db) report_hash[row[:x].to_s(:db)] = row[:y].to_s(:db)
end end
(@extra[:start_date]..@extra[:end_date]).each do |date| (@extra[:start_date].to_date..@extra[:end_date].to_date).each do |date|
yield [date.to_s(:db), report_hash.fetch(date.to_s(:db), 0)] yield [date.to_s(:db), report_hash.fetch(date.to_s(:db), 0)]
end end
end end