ADD format time method

This commit is contained in:
Jasder 2020-11-04 11:21:51 +08:00
parent cfb794c94f
commit 58d8c911a8
3 changed files with 12 additions and 2 deletions

View File

@ -62,4 +62,14 @@ module RepositoriesHelper
return content
end
# unix_time values for example: 1604382982
def render_format_time_with_unix(unix_time)
Time.at(unix_time).strftime("%Y-%m-%d %H:%M")
end
# date for example: 2020-11-01T19:57:27+08:00
def render_format_time_with_date(date)
date.to_time.strftime("%Y-%m-%d %H:%M")
end
end

View File

@ -9,5 +9,6 @@ json.committer do
end
json.timestamp render_unix_time(commit['Committer']['When'])
json.time_from_now time_from_now(commit['Committer']['When'])
json.created_at render_format_time_with_date(commit['Committer']['When'])
json.message commit['CommitMessage']
json.sha commit['Sha']

View File

@ -1,8 +1,7 @@
created_at = Time.at(entry['latest_commit']['created_at'].to_i).strftime("%Y-%m-%d %H:%M")
json.commit do
json.message entry['latest_commit']['message']
json.sha entry['latest_commit']['sha']
json.created_at created_at
json.created_at render_format_time_with_unix(entry['latest_commit']['created_at'].to_i)
json.time_from_now time_from_now(created_at)
json.created_at_unix entry['latest_commit']['created_at']
end