-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add relative date formatting for date/datetime columns
- Loading branch information
1 parent
040d7de
commit b1e8517
Showing
5 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# rubocop:disable Naming/MethodName | ||
module Koi | ||
module DateHelper | ||
# @deprecated | ||
def date_format(date, format) | ||
date.strftime format.gsub(/yyyy/, "%Y") | ||
.gsub(/yy/, "%y") | ||
.gsub(/Month/, "%B") | ||
.gsub(/M/, "%b") | ||
.gsub(/mm/, "%m") | ||
.gsub(/m/, "%-m") | ||
.gsub(/Day/, "%A") | ||
.gsub(/D/, "%a") | ||
.gsub(/dd/, "%d") | ||
.gsub(/d/, "%-d") | ||
end | ||
|
||
# @deprecated | ||
def date_Month_d_yyyy(date) | ||
date.strftime "%B %-d, %Y" | ||
end | ||
|
||
# @deprecated | ||
def date_d_Month_yyyy(date) | ||
date.strftime "%-d %B %Y" | ||
end | ||
def distance_from_now | ||
from_time = value.to_time | ||
to_time = Date.current.to_time | ||
distance_in_days = ((to_time - from_time) / (24.0 * 60.0 * 60.0)).round | ||
|
||
# @deprecated | ||
def date_d_M_yy(date) | ||
date.strftime "%-d %b %y" | ||
case distance_in_days | ||
when 0 | ||
"today" | ||
when 1 | ||
"yesterday" | ||
when -1 | ||
"tomorrow" | ||
when 2..5 | ||
"#{distance_in_days} days ago" | ||
when -5..-2 | ||
"#{distance_in_days.abs} days from now" | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable Naming/MethodName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<% row.ordinal %> | ||
<% row.link :name %> | ||
<% row.image :image %> | ||
<% row.datetime :created_at %> |