Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2015 22:34
Show Gist options
  • Save anonymous/5448843cb8bf080b1cb5 to your computer and use it in GitHub Desktop.
Save anonymous/5448843cb8bf080b1cb5 to your computer and use it in GitHub Desktop.
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