Skip to content

Instantly share code, notes, and snippets.

@hanachin
Last active December 24, 2018 15:37
Show Gist options
  • Save hanachin/f2194b75e296b24592bb36b60f31cc6d to your computer and use it in GitHub Desktop.
Save hanachin/f2194b75e296b24592bb36b60f31cc6d to your computer and use it in GitHub Desktop.
Re: 10分間隔で 10時〜23時台の配列をつくる ref: https://qiita.com/hanachin_/items/1a7b9ea0af62e5021c94
("10:00".."23:50").step(10).select {|t| t.match?(/:[0-5]0/) }
(1000..2350).step(10).select {|t| t % 100 < 60 }.map(&:to_s).each {|s| s[2,0] = ?: }
("10".."23").to_a.product(("00".."50").step(10).to_a).map {|t| t.join(?:) }
("10".."23").flat_map {|h| ("00".."50").step(10).map {|m| "#{h}:#{m}" } }
Time.new(0, 1, 1, 10, 0).then {|t| loop.lazy.map { t.tap { t += 10 * 60 } }.take_while {|t| t <= Time.new(0, 1, 1, 23,
50) }.map {|t| t.strftime("%H:%M") }.to_a }
Enumerator.new {|y| t = Time.new(0, 1, 1, 10, 0); while t <= Time.new(0, 1, 1, 23, 50); y << t.strftime("%H:%M"); t +=10 * 60; end }.to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment