From 2656b83ae88fd0a56eea9e9254446d7395d09e95 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 4 Aug 2020 14:48:46 +0800 Subject: [PATCH] Fix time zone problem. --- app/models/e_paper_topic.rb | 2 +- app/models/paper_criteria.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/e_paper_topic.rb b/app/models/e_paper_topic.rb index fbf49b3..a57e1db 100644 --- a/app/models/e_paper_topic.rb +++ b/app/models/e_paper_topic.rb @@ -24,6 +24,6 @@ class EPaperTopic end def criteria_title - PaperCriteria.where(:start_date.lte => self.period, :end_date.gte => self.period).first.title rescue "" + PaperCriteria.where(:start_date.lte => self.period.in_time_zone(Time.zone.utc_offset / 3600), :end_date.gte => self.period.in_time_zone(Time.zone.utc_offset / 3600)).first.title rescue "" end end \ No newline at end of file diff --git a/app/models/paper_criteria.rb b/app/models/paper_criteria.rb index 8569e22..a927f1e 100644 --- a/app/models/paper_criteria.rb +++ b/app/models/paper_criteria.rb @@ -16,8 +16,8 @@ class PaperCriteria def epaper_topics - tmp = EPaperTopic.where(:period.gte => self.start_date, :period.lte => self.end_date).can_display - tmp = EPaperTopic.where(:period.gte => self.start_date, :period.lte => self.end_date).limit(1) if tmp.first.nil? + tmp = EPaperTopic.where(:period.gte => self.start_date.in_time_zone(Time.zone.utc_offset / 3600), :period.lte => self.end_date.in_time_zone(Time.zone.utc_offset / 3600)).can_display + tmp = EPaperTopic.where(:period.gte => self.start_date.in_time_zone(Time.zone.utc_offset / 3600), :period.lte => self.end_date.in_time_zone(Time.zone.utc_offset / 3600)).limit(1) if tmp.first.nil? tmp end