Skip to content

Instantly share code, notes, and snippets.

@takafumir
Last active December 28, 2016 05:37
Show Gist options
  • Save takafumir/6fd1eef86c37faf8fe40 to your computer and use it in GitHub Desktop.
Save takafumir/6fd1eef86c37faf8fe40 to your computer and use it in GitHub Desktop.
Create a todo formated file for this year. Ref. http://easyramble.com/how-to-manage-tasks-simply.html
#!/usr/bin/env ruby
require "date"
def this_year
( ARGV[0] || DateTime.now.year ).to_i
end
def leap_year?
Date.new(this_year).leap?
end
def last_day
leap_year? ? 365 : 364
end
TODO_FILE_BASENAME = "DailyToDo"
gantan = DateTime.new(this_year, 1, 1, 0, 0, 0, "+0900")
todo_file = "./#{TODO_FILE_BASENAME}_#{this_year}.txt"
if File.exist?(todo_file)
warn "Todo file was not created. This year's todo file already exists."
exit
end
open(todo_file, "w") do |f|
f.write <<EOS
***************** #{TODO_FILE_BASENAME} #{this_year} *****************
- : todo
= : doing
+ : done
**************************************************
EOS
(0..last_day).each do |d|
f.write "[#{(gantan + d).strftime("%Y/%m/%d %A")}]\n\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment