diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index a845b70c5..10ad1377e 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -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 diff --git a/app/views/pull_requests/_commit.json.jbuilder b/app/views/pull_requests/_commit.json.jbuilder index 023c2f302..0b7db5893 100644 --- a/app/views/pull_requests/_commit.json.jbuilder +++ b/app/views/pull_requests/_commit.json.jbuilder @@ -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'] diff --git a/app/views/repositories/_last_commit.json.jbuilder b/app/views/repositories/_last_commit.json.jbuilder index 9d6bbe345..56823b770 100644 --- a/app/views/repositories/_last_commit.json.jbuilder +++ b/app/views/repositories/_last_commit.json.jbuilder @@ -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