Refine codes when postdate is nil.

This commit is contained in:
邱博亞 2024-04-25 21:41:54 +08:00
parent fc14bb8105
commit a9f96e0d22
2 changed files with 11 additions and 9 deletions

View File

@ -637,7 +637,7 @@ class AnnouncementsController < ApplicationController
anns = top_anns + rest_anns
end
end
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil }
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') if a["postdate"] }
anns
end
@ -814,7 +814,7 @@ class AnnouncementsController < ApplicationController
"title" => announcement.title,
"subtitle_ann" => subtitle_ann,
"update_user" => update_user,
"updated_at" => (announcement.postdate.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue ""),
"updated_at" => (announcement.postdate ? announcement.postdate.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') : ""),
"body" =>announcement.text,
"image" => announcement.image.url,
"img_src" => img_src,
@ -878,7 +878,7 @@ class AnnouncementsController < ApplicationController
OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => announcement["title_translations"][locale]},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => announcement["image"]["original"]},{"property" => "og:type", "content" => "Article"}])
datetime = DateTime.parse(announcement["postdate"])
datetime = announcement["postdate"] ? DateTime.parse(announcement["postdate"]) : nil
bulletin_carousel_images = Array(announcement["bulletin_carousel_images"])
resume_btn_title = (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume"

View File

@ -146,12 +146,14 @@ module AnnouncementsHelper
end
flag = title.include?(keywords.to_s)
end
if sflag && !eflag
flag = flag && (anns.postdate<=etime)
elsif !sflag && eflag
flag = flag && (anns.postdate>=stime)
elsif !sflag && !eflag
flag = flag && (anns.postdate>=stime) && (anns.postdate<=etime)
if anns.postdate
if sflag && !eflag
flag = flag && (anns.postdate<=etime)
elsif !sflag && eflag
flag = flag && (anns.postdate>=stime)
elsif !sflag && !eflag
flag = flag && (anns.postdate>=stime) && (anns.postdate<=etime)
end
end
flag
}