Created
February 21, 2015 22:34
-
-
Save anonymous/5448843cb8bf080b1cb5 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.map { |s1, s2| s2 } | |
end | |
end | |
list = [Time.new(2000, 1, 1), Time.new(2000, 1, 1)] | |
results = list.zip([nil, *list]).map do |t2, t1| | |
date_conv(t1, t2) | |
end | |
p results.map(&:join).map(&:strip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment