Module: Kaui::DateHelper

Defined in:
app/helpers/kaui/date_helper.rb

Constant Summary collapse

LOCAL_DATE_RE =
/^\d+-\d+-\d+$/

Instance Method Summary collapse

Instance Method Details

#format_date(date, timezone = "Pacific Time (US & Canada)") ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/kaui/date_helper.rb', line 6

def format_date(date, timezone="Pacific Time (US & Canada)")

  # Double check this is not null
  return nil if date.nil?

  # If this is a local date we assume this is already in the account timezone, and so there is nothing to do
  return date.to_s if LOCAL_DATE_RE.match(date.to_s)

  # If not, convert into account timezone and return the date part only
  parsed_date = DateTime.parse(date.to_s).in_time_zone(timezone)
  parsed_date.to_s(:date_only)
end