Created
March 13, 2016 08:07
-
-
Save sunkibaek/84c830c4329569d74679 to your computer and use it in GitHub Desktop.
NullDateTime
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
class NullDateTime | |
def in_time_zone(_city = 'DefaultTimeZoneCity') | |
self | |
end | |
def to_s(_format = :default_date_time) | |
'' | |
end | |
end |
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
# app/models/order.rb | |
def completed? | |
completed_at? | |
end |
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
# app/models/order.rb | |
def completed_at | |
super || NullDateTime.new | |
end |
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
# app/views/orders/show.html.erb | |
order.completed_at.to_s(:short) |
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
# app/views/orders/show.html.erb | |
<% if order.completed? %> | |
<%= order.completed_at.to_s(:short) %><br> | |
<%= order.completed_at.in_time_zone('Seoul') %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment