Fix date format bug.

This commit is contained in:
BoHung Chiu 2022-02-10 17:47:38 +08:00
parent f3ab02e1f7
commit 54b2e4698c
1 changed files with 14 additions and 4 deletions

View File

@ -174,11 +174,21 @@ class EventNews
parse_format = self.date_parse_format
if s.to_date == e.to_date
parse_format_arr = parse_format.split(/(%d %a|%d) /)
parse_format_arr = parse_format_arr[0..-2].join(""), parse_format_arr[-1]
if parse_format_arr.count > 1
parse_format_arr = parse_format_arr[0..-2].join(""), parse_format_arr[-1]
end
date_str = custom_strftime(s, parse_format_arr[0])
s_time = s.strftime(parse_format_arr[1])
e_time = e.strftime(parse_format_arr[1])
"#{date_str} #{s_time} ~ #{e_time}"
s_time = s.strftime(parse_format_arr[1].to_s)
e_time = e.strftime(parse_format_arr[1].to_s)
if e_time.present?
if s_time != e_time
"#{date_str} #{s_time} ~ #{e_time}"
else
"#{date_str} #{s_time}"
end
else
date_str
end
else
custom_strftime(s, self.date_parse_format) + " ~ " + custom_strftime(e, self.date_parse_format)
end