FIX: Show correct dates in topic timelines (#13670)

The date shown in topic timeline was one day later if the post at that
position was made near midnight. This happened because the days number
was rounded down.
This commit is contained in:
Bianca Nenciu 2021-07-12 19:35:24 +03:00 committed by GitHub
parent 953fd2cb50
commit f74640ac58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -608,7 +608,7 @@ class TopicView
columns = [:id] columns = [:id]
if !is_mega_topic? if !is_mega_topic?
columns << 'EXTRACT(DAYS FROM CURRENT_TIMESTAMP - posts.created_at)::INT AS days_ago' columns << '(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP - posts.created_at) / 86400)::INT AS days_ago'
end end
posts.pluck(*columns) posts.pluck(*columns)

View File

@ -796,13 +796,13 @@ describe TopicView do
end end
describe '#filtered_post_stream' do describe '#filtered_post_stream' do
let!(:post) { Fabricate(:post, topic: topic, user: first_poster) } let!(:post) { Fabricate(:post, topic: topic, user: first_poster, created_at: 18.hours.ago) }
let!(:post2) { Fabricate(:post, topic: topic, user: evil_trout) } let!(:post2) { Fabricate(:post, topic: topic, user: evil_trout, created_at: 6.hours.ago) }
let!(:post3) { Fabricate(:post, topic: topic, user: first_poster) } let!(:post3) { Fabricate(:post, topic: topic, user: first_poster) }
it 'should return the right columns' do it 'should return the right columns' do
expect(topic_view.filtered_post_stream).to eq([ expect(topic_view.filtered_post_stream).to eq([
[post.id, 0], [post.id, 1],
[post2.id, 0], [post2.id, 0],
[post3.id, 0] [post3.id, 0]
]) ])