Last active
August 29, 2015 14:15
-
-
Save yuki-yano/dd0ac75a8daae6396ed4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def date_to_a(t) | |
| [ | |
| "#{t.year}年", | |
| "#{t.month}月", | |
| "#{t.day}日", | |
| " #{t.hour}時#{t.min}分", | |
| ] | |
| end | |
| def date_conv(t1, t2) | |
| case t1 | |
| when nil | |
| date_to_a(t2) | |
| when t2 | |
| ["#{t2.hour}時#{t2.min}分"] | |
| else | |
| rest = date_to_a(t1).zip(date_to_a(t2)).drop_while do |s1, s2| | |
| s1 == s2 | |
| end | |
| rest.last | |
| end | |
| end | |
| list = [Time.new(2000, 1, 1), Time.new(2000, 1, 1)] | |
| results = list.zip([nil, *list]).map { |t2, t1| date_conv(t1, t2) } | |
| p results.map(&:join).map(&:strip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment