Sha256: d3e30c3bcb26c2e14e417ba1d374b9c028feb1419893bafc3a9a8d12838db114

Contents?: true

Size: 1.04 KB

Versions: 65

Compression:

Stored size: 1.04 KB

Contents

module Account::DatesHelper
  # e.g. October 11, 2018
  def display_date(timestamp)
    return nil unless timestamp
    if local_time(timestamp).year == local_time(Time.now).year
      local_time(timestamp).strftime("%B %-d")
    else
      local_time(timestamp).strftime("%B %-d, %Y")
    end
  end

  # e.g. October 11, 2018 at 4:22 PM
  # e.g. Yesterday at 2:12 PM
  # e.g. April 24 at 7:39 AM
  def display_date_and_time(timestamp)
    return nil unless timestamp

    # today?
    if local_time(timestamp).to_date == local_time(Time.now).to_date
      "Today at #{display_time(timestamp)}"
    # yesterday?
    elsif (local_time(timestamp).to_date) == (local_time(Time.now).to_date - 1.day)
      "Yesterday at #{display_time(timestamp)}"
    else
      "#{display_date(timestamp)} at #{display_time(timestamp)}"
    end
  end

  # e.g. 4:22 PM
  def display_time(timestamp)
    local_time(timestamp).strftime("%l:%M %p")
  end

  def local_time(time)
    return time if current_user.time_zone.nil?
    time.in_time_zone(current_user.time_zone)
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
bullet_train-1.0.75 app/helpers/account/dates_helper.rb
bullet_train-1.0.74 app/helpers/account/dates_helper.rb
bullet_train-1.0.72 app/helpers/account/dates_helper.rb
bullet_train-1.0.71 app/helpers/account/dates_helper.rb
bullet_train-1.0.70 app/helpers/account/dates_helper.rb
bullet_train-1.0.69 app/helpers/account/dates_helper.rb
bullet_train-1.0.68 app/helpers/account/dates_helper.rb
bullet_train-1.0.67 app/helpers/account/dates_helper.rb
bullet_train-1.0.66 app/helpers/account/dates_helper.rb
bullet_train-1.0.65 app/helpers/account/dates_helper.rb
bullet_train-1.0.64 app/helpers/account/dates_helper.rb
bullet_train-1.0.63 app/helpers/account/dates_helper.rb
bullet_train-1.0.62 app/helpers/account/dates_helper.rb
bullet_train-1.0.61 app/helpers/account/dates_helper.rb
bullet_train-1.0.60 app/helpers/account/dates_helper.rb
bullet_train-1.0.59 app/helpers/account/dates_helper.rb
bullet_train-1.0.58 app/helpers/account/dates_helper.rb
bullet_train-1.0.57 app/helpers/account/dates_helper.rb
bullet_train-1.0.56 app/helpers/account/dates_helper.rb
bullet_train-1.0.53 app/helpers/account/dates_helper.rb