Skip to content

Instantly share code, notes, and snippets.

@yuki-yano
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save yuki-yano/dd0ac75a8daae6396ed4 to your computer and use it in GitHub Desktop.

Select an option

Save yuki-yano/dd0ac75a8daae6396ed4 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.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